Home·Terminal commands

crontab

Processes and system

Usage

crontab -e | crontab -l

Edits the per-user schedule table; cron runs with almost no PATH and never reads your login profile, so write absolute paths, and `crontab -r` erases the whole table without asking.

Common flags

FlagMeaning
-eEdit your table in $EDITOR; it is installed when you save.
-lPrint your table. Redirect it somewhere to keep a backup.
-rDelete the whole table at once, with no confirmation.
-u <user>Work on another user's table (root only).
m h dom mon dowThe five time fields, then the command. * means every.
@reboot / @dailyShorthand instead of the five fields.

Examples

crontab -l > ~/cron.bak

Back up the table before touching it.

crontab -e

Then add: 0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

crontab -l | grep -v backup.sh | crontab -

Remove one line without opening an editor.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does crontab do?

Edits the per-user schedule table; cron runs with almost no PATH and never reads your login profile, so write absolute paths, and `crontab -r` erases the whole table without asking.

Q. How do I type it?

crontab -e | crontab -l — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

6 are listed here; the full set is in man crontab. This command sits under Processes and system.

Related commands

man page: man crontab