Linux and Unix crontab command
Quick links
About crontab
Syntax
Examples
Related commands
Linux and Unix main page
List of files that you want to run on a regular schedule.
crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]
| -u | It specifies the name of the user whose crontab is to be tweaked. If this option is not given, crontab examines "your" crontab, i.e., the crontab of the person executing the command. Note that su can confuse crontab and that if you are running inside of su you should always use the -u option for safety's sake. The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename "-" is given. |
| -l | The current crontab will be displayed on standard output. |
| -r | The current crontab will be be removed. |
| -e | This option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically. |
| -i | This option modifies the -r option to prompt the user for a 'y/Y' response before actually removing the crontab. |
| -s | It will append the current SELinux security context string as an MLS_LEVEL setting to the crontab file before editing / replacement occurs - see the documentation of MLS_LEVEL in crontab. |
Lines that can be in the crontab file.
minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).
crontab -e
Edits the crontab file to be used.
0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.
Below is a table that represents what each of the above fields are for.
| min | hour | dayofmonth | monthofyear | dayofweek | command |
| 0 | 12 | 14 | 2 | * | mailx john%Happy Birthday!%Time for lunch. |
| Options | Explanation |
| * | Is treated as a wild card. Meaning any possible value. |
| */5 | Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with another numerical value will change this option. |
| 2,4,6 | Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-clock. |
| 9-17 | Treats for any value between 9 and 17. So if placed in day of month this would be days 9 through 17. Or if put in hours it would be between 9 and 5. |
If you wish to create a task to be performed once later during the day you may wish to consider using the at command.
