System and processes

The crontab command

Manages cron's scheduled jobs: commands that run at fixed times or intervals, such as backups or cleanups. Each user has their own table. Times follow the system's time zone.

Syntax

crontab [-u usuario] [-l | -e | -r | archivo]Try it in the terminal →

Most useful options

-lShows the current table of the user.
-eOpens the table in the default editor (EDITOR variable). Saving installs it.
-rDeletes the whole table without asking. It is dangerous: there is no recycle bin.
-iAsks for confirmation before deleting with -r.
-u <usuario>Manages another user's table. Only root can do this.
<archivo>Installs the table from that file, replacing the current one.

Copy-ready examples

$ crontab -lLists the jobs: each line has minute, hour, day, month, weekday and command.

Example output

# m h dom mon dow command
30 2 * * 0 /home/miguel/backup.sh
*/5 * * * * /usr/bin/uptime >> /tmp/uptime.log
$ crontab -eOpens the editor. Add a line, save and close: crontab installs it on save.
$ crontab mi-tabla.txtInstalls a whole table from a file, replacing the previous one without asking.
$ */15 * * * * df -h / >> ~/disco.log 2>&1A table line: every 15 minutes it appends free disk space to a log.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
no crontab for miguelThe user has no table yet: this is normal the first time.Create the first job with crontab -e.
errors in crontab file, can't install.There is a syntax error, almost always a time field out of range or a missing field.Fix the line it points to and install again; the previous table stays active meanwhile.
crontab: must be privileged to use -uWithout root you are trying to manage another user's table.Use sudo crontab -u user -e, or manage your own table without -u.

Typical mistakes

  • cron uses a minimal PATH: give absolute paths, such as /usr/bin/python3, in every command.

Differences from similar commands

  • at: Runs a command once, at a future time. cron repeats each job on its schedule.
  • systemctl: systemd timers are the modern alternative: with Persistent=true they catch up on runs missed while the machine was off.

Security

Each line runs with the permissions of the table's owner: as root, it can touch the whole system. Do not put passwords on the command line, because they end up in ps and in logs; use a file with 600 permissions. And do not leave scripts writable by others: cron will run them anyway.

Related commands

FAQ

How do I check that it ran?

Redirect the output to a log and check journalctl -u cron on Debian or Ubuntu; on other distros, /var/log/cron.

Why does it not run if the machine is off at that hour?

Cron does not catch up on missed runs. anacron or systemd timers with Persistent=true exist for that. Both run the job after boot.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course