time division; for example, */4 for hours means “every 4 hours all day,” and
0-12/3 means “every 3 hours from midnight to noon.” You can also specify
day and month names rather than numbers, using three-character
abbreviations: Sun, Mon, Tue, Fri, Sat for days or Jan, Feb, Mar, Oct, Nov,
Dec for months.
As well as system jobs, there are user jobs for those users who have the
correct permissions. User jobs are stored in the /var/spool/cron
directory, with each user having his own file named after his username (for
instance, /var/spool/cron/philip or /var/spool /cron/root).
These files contain the jobs the user wants to run and take roughly the same
format as the /etc/crontab file, with the exception that the owner of
the job should not be specified because it is always the same as the filename.
To edit your own crontab file, type crontab -e. This brings up a text
editor, where you can enter your entries. (By default the editor is vim, also
known by its older name vi, but you can set the EDITOR environment
variable to change that.) The format of this file is a little different from the
format for the main crontab file because in this case there is no need to
specify the owner of the job, as it is always you.
So, this time each line is made up of six fields: minute (0–59), hour (0–23),
day of the month (1–31), month of the year (1–12), day of the week (0–7),
and the command to run. If you are using vim and are new to it, press i to
enter insert mode to edit your text; then press Esc to exit insert mode. To save
and quit, type a colon followed by wq and press Enter.
When programming, we tend to use a sandbox subdirectory in our home
directory where we keep all sorts of temporary files that we were just playing
around with. We can use a personal job to empty that directory every morning
at 6:00 a.m. to get a fresh start each morning. Here is how that would look in
our crontab file:
Click here to view code image
0 6 rm –rf /home/matthew/sandbox/
If you are not allowed to schedule jobs, you will be stopped from editing your
crontab file.
After your jobs are placed, you can use the command crontab -l to list
your jobs. This just prints the contents of your crontab file, so its output is
the same as the line you just entered.
If you want to remove just one job, the easiest thing to do is type crontab -
e to edit your crontab file in vim; then, after having moved the cursor to