Linux Commands - crontab (schedule reoccurring jobs)

Ensure the cron daemon in running

Before using cron, ensure the cron daemon is enabled and running. The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable crond.

systemctl start crond
systemctl enable crond


If your system is using init, use the service command to start and enable crond.

service crond start
service crond enable


Viewing the cron table

The crontab -l (list) command can be used to view the entries in crontab. If the -u (user) option is not included, the current users cron table will be displayed.

crontab -l


Or the -u option can be used to display a certain users cron table.

crontab -l -u john.doe


Something like this could be returned.

00 01 * * * bash /etc/cron.daily/


If there are no crontab entries, the /var/spool/cron directory will be empty, or the /var/spool/cron/username file will be empty, and be 0 bytes.

ls -l /var/spool/cron

-rw-------. 1 root root    0 Aug  7 21:20 root


On the other hand, if there are crontab entries, the /var/spool/cron/username file can be viewed to view each users cron table.

cat /var/spool/cron/root

00 01 * * * bash /etc/cron.daily/


Edit cron table

The crontab -e (edit) command can be used to edit the current users cron table, or the -u option can be included to specify a specifc user. In this example, John Doe's cron table will be edited.

[john.doe@server1 ~]# crontab -e


Hourly, Daily, Weekly, Monthly, Reboot

The @ symbol can be used to run a command or script once every hour, once every day, once every week, once every month, or when the server is restarted.

@hourly  bash /home/JohnDoe/scripts/
@daily   bash /home/JohnDoe/scripts/
@weekly  bash /home/JohnDoe/scripts/
@monthly bash /home/JohnDoe/scripts/
@reboot  bash /home/JohnDoe/scripts/


The sleep option can be used to wait a while before running a script after reboot. In this example, is run 1 minute after reboot.

@reboot sleep 60 && bash /home/JohnDoe/scripts/


Crontab can be used to run bash shell scripts, or commands. For example, here is how you would schedule the reboot command to occur daily at 1:00 am.

00 01 * * * /sbin/reboot


Specific date time

You can specify an exact date and time to run a command or script. The syntax of the lines in the cron table is: <minute> <hour> <day of the month> <month> <day of the week> <command or script to execute>. For example, to run every day at 1:00 am:

00 01 * * * bash /home/JohnDoe/scripts/


Or, to remove every file in the /tmp directory every day at 1:00 am.

00 01 * * * /bin/rm /tmp/*


The first 5 fields of crontab are:

  • minute (0-59)
  • hour (0-23)
  • day of the month (1-31)
  • month (1-12)
  • day of the week (0-7)
    • 0 = Sunday
    • 1 = Monday
    • 2 = Tuesday
    • 3 = Wednesday
    • 4 = Thursday
    • 5 = Friday
    • 6 = Saturday
    • 7 = Sunday



Each field can accept a range. For example, to run at 1:00 am, Monday through Friday:

00 01 * * 1-5 bash /etc/cron.daily/


Comma separated lists

Fields can also accept a comma separated list. For example, to run at 1:00 am on Saturday and Sunday:

00 01 * * 6,7 bash /etc/cron.daily/


Once every x minutes

All astericks can be used to run a cron job once every minute.

* * * * * bash /etc/cron.daily/


Or, in this example, will be run once every 15 minutes, on the hour and then 15 minutes, then 30 minutes, then 45 minutes after the hour.

*/15 * * * * bash /etc/cron.daily/


Or, in this example, will be run once every 15 minutes as long as minute is 2-59. In other words, will not run at 00 or 01 minutes.

2-59/15 * * * * bash /etc/cron.daily/



Variables can be defined in the cron table. In this example, the FOO variable contains a value of bar. In this example, bar would be appended to out.txt once every minute.

* * * * * echo $FOO >> out.txt


Removing cron tables

The crontab -r (remove) command can be used to remove a users entire cron table. For example, to remove user1 cron table:

crontab -r


Cron log

Refer to Linux Files - cron log.

Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 9deab in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |