How to manage crontab tasks

Cron is a time-based job scheduler in Unix-like operating systems. You can use it for running tasks on a regular interval.

Crontab is a command that lets you to manage list of tasks.

How to list crontab entries of current user

user@host:~$ crontab -l
# m h dom mon dow command
* 22 * * * /usr/local/bin/backup.sh

How to edit crontab

It will open text editor and allows you to manually create or edit cron tasks.

user@host:~$ crontab -e

How to backup all crontab entries

user@host:~$ crontab -l > cron-backup.txt
user@host:~$ cat cron-backup.txt
# m h dom mon dow command
* 22 * * * /usr/local/bin/backup.sh 

How to remove all crontab entries

user@host:~$ crontab -r
user@host:~$ crontab -l
no crontab for user

How to install or restore crontab from file

This one is very useful if you want to install crontab during automated deployment process.

user@host:~$ crontab cron-backup.txt
user@host:~$ crontab -l
# m h dom mon dow command
* 22 * * * /usr/local/bin/backup.sh