The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


crontab - schedule periodic background work


crontab [file]

crontab [ -e | -l | -r ]


The crontab utility creates, replaces or edits a user's crontab entry; a crontab entry is a list of commands and the times at which they are to be executed. The new crontab entry can be input by specifying file or input from standard input if no file operand is specified, or by using an editor, if -e is specified.

Upon execution of a command from a crontab entry, the implementation will supply a default environment, defining at least the following environment variables:

A pathname of the user's home directory.
The user's login name.
A string representing a search path guaranteed to find all of the standard utilities.
A pathname of the command interpreter. When crontab is invoked as specified by this specification, the value will be a pathname for sh.

The values of these variables when crontab is invoked as specified by this specification will not affect the default values provided when the scheduled command is run.

If standard output and standard error are not redirected by commands executed from the crontab entry, any generated output or errors will be mailed, via an implementation-dependent method, to the user.

Users are permitted to use crontab if their names appear in the file /usr/lib/cron/cron.allow. If that file does not exist, the file /usr/lib/cron/cron.deny is checked to determine if the user should be denied access to crontab. If neither file exists, only a process with appropriate privileges is allowed to submit a job. If only cron.deny exists and is empty, global usage is permitted. The cron.allow and cron.deny files consist of one user name per line.


The crontab utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

Edit a copy of the invoking user's crontab entry, or create an empty entry to edit if the crontab entry does not exist. When editing is complete, the entry will be installed as the user's crontab entry.
(The letter ell.) List the invoking user's crontab entry.
Remove the invoking user's crontab entry.


The following operand is supported:
The pathname of a file that contains specifications, in the format defined in the INPUT FILES section, for crontab entries.


See the INPUT FILES section.


In the POSIX locale, a crontab entry must be a text file consisting of lines of six fields each. The fields must be separated by blank characters. The first five fields must be integer patterns that specify the following:

  1. Minute (0-59)

  2. Hour (0-23)

  3. Day of the month (1-31)

  4. Month of the year (1-12)

  5. Day of the week (0-6 with 0=Sunday).

Each of these patterns can be either an asterisk (meaning all valid values), an element or a list of elements separated by commas. An element must be either a number or two numbers separated by a hyphen (meaning an inclusive range). The specification of days can be made by two fields (day of the month and day of the week). If month, day of month and day of week are all asterisks, every day will be matched. If either the month or day of month is specified as an element or list, but the day of week is an asterisk, the month and day of month fields will specify the days that match. If both month and day of month are specified as asterisk, but day of week is an element or list, then only the specified days of the week will match. Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month or the day of week, will be matched.

The sixth field of a line in a crontab entry is a string that will be executed by sh at the specified times. A percent sign character in this field will be translated to a newline character. Any character preceded by a backslash (including the %) causes that character to be treated literally. Only the first line (up to a "%" or end-of-line) of the command field will be executed by the command interpreter. The other lines will be made available to the command as standard input.

Blank lines and those whose first non-blank character is "#" will be ignored.

The text files /usr/lib/cron/cron.allow and /usr/lib/cron/cron.deny contain user names, one per line, of users who are, respectively, authorised or denied access to the service underlying the crontab utility.


The following environment variables affect the execution of crontab:
Determine the editor to be invoked when the -e option is specified. The default editor is vi.
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




If the -l option is specified, the crontab entry will be written to the standard output.


Used only for diagnostic messages.






The following exit values are returned:
Successful completion.
An error occurred.


The user's crontab entry is not submitted, removed, edited or listed.


The format of the crontab entry shown here is guaranteed only for the POSIX locale. Other cultures may be supported with substantially different interfaces, although implementations are encouraged to provide comparable levels of functionality.

The default settings of the HOME , LOGNAME , PATH and SHELL variables that are given to the scheduled job are not affected by the settings of those variables when crontab is run; as stated, they are defaults. The text about "invoked as specified by this specification" means that the implementation may provide extensions that allow these variables to be affected at runtime, but that the user has to take explicit action in order to access the extension, such as give a new option flag or modify the format of the crontab entry.

A typical user error is to type only crontab; this will cause the system to wait for the new crontab entry on standard input. If end-of-file is typed (generally <control>-D), the crontab entry will be replaced by an empty file. In this case, the user should type the interrupt character, which will prevent the crontab entry from being replaced.


  1. Clean up core files every weekday morning at 3:15 am:
    15 3 * * 1-5 find $HOME -name core 2>/dev/null | xargs rm -f

  2. Mail a birthday greeting:
    0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.

  3. As an example of specifying the two types of days:
    0 0 1,15 * 1
    would run a command on the first and fifteenth of each month, as well as on every Monday. To specify days by only one field, the other field should be set to "*"; for example:
    0 0 * * 1
    would run a command only on Mondays.





UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]