From aldeid
Jump to navigation Jump to search
This article is also available in one or more other languages
To view this article in French, click here
You might also see: cron


Crontab is an interface that enables to edit cron tables, located in /var/spool/cron/crontabs. These tables don't have to be manually edited. They enable to plan jobs.


Basic usage is as follows:

crontab [-u user] file
crontab [-u user] { -e | -l | -r }


Edit <user>'s crontab
List <user>'s crontab
Purge crontab of <user>

Environment variables

To change default editor (nano), you can define $EDITOR environment variable as follows:

export EDITOR=/usr/bin/vim

To make this variable known each time you boot your machine, insert this line in your ~/.bashrc.

To avoid to accidentally remove crontab with the -r option, you can also define an alias to replace the command:

alias crontab="crontab -i"

The -i parameter enables to display a confirmation before deleting a crontab.

crontab syntax

Each line of a crontab must be formatted as follows, with a space or tab between each item:

24 3 * * 1 root /foo/bar/
0-59 0-23 1-31 1-12 0-7    ╰➙ Script to execute
 ╰➙ Command will be launched as root
 ╰➙ Day of week (1=Monday, 2=Tuesday, ..., 7=0=Sunday)
 ╰➙ Month (1=January, 2=February, ..., 12=December)
 ╰➙ Day of month
 ╰➙ Hour
 ╰➙ Minute


To launch a task every minute:

* * * * * root /every/minute/

To launch a task every 5 minutes:

*/5 * * * * root /every/fiveminutes/

To launch a task every Tuesday, at 04:30 AM :

30 4 * * 2 root /every/tuesday/