Name

crontab — stdin  stdout  - file  -- opt  --help  --version

Synopsis

crontab [options] [file]

The crontab command, like at, schedules jobs for specific times. However, crontab is for recurring jobs, such as “Run this command at midnight on the second Tuesday of each month.” To make this work, you edit and save a file (called your crontab file), which automatically gets installed in a system directory (/var/at/tabs). Once a minute, an OS X process called cron wakes up, checks your crontab file, and executes any jobs that are due:

crontab -e

Edit your crontab file in your default editor ($EDITOR)

crontab -l

Print your crontab file on standard output

crontab -r

Delete your crontab file

crontab myfile

Install the file myfile as your crontab file

sudo crontab ...

Work with the root user’s crontab file to run administrative system processes

sudo crontab -u smith ...

Work with user smith’s crontab file

Crontab files contain one job per line. (Blank lines and comment lines beginning with “#” are ignored.) Each line has six fields, separated by whitespace. The first five fields specify the time to run the job, and the last is the job command itself. The first five fields are:

Minutes of the hour

Integers between 0 and 59. This can be a single number (30), a sequence of numbers separated by commas (0,15,30,45), a range (20–30), a sequence of ranges (0–15,50–59), or an asterisk to mean “all.” You can also specify “every nth time” with the suffix /n; for instance, both */12 and 0–59/12 mean ...

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.