
Category: Linux
Posted at: Jul 12, 2025
2 Minutes Read
Cron is a time-based job scheduler used in unix operating systems such as Linux and macOS. it has two main components:
Where does the name "cron" come from? The word cron comes from the Greek word chronos, which means time.
Cron jobs have a special format that looks like this:
* * * * * command_to_execute | | | | | | | | | └─── Day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat | | | └────── Month (1 - 12) OR jan,feb,mar,apr... | | └───────── Day of the month (1 - 31) | └──────────── Hour (0 - 23) └─────────────── Minute (0 - 59)
And here are some examples:
Runs every minute
* * * * * /home/user/backup.sh
Runs every day at 12:00 AM
0 0 * * * /home/user/backup.sh
Runs every Thursday at 4:00 PM
0 16 * * 4 /home/user/backup.sh
To add, modify or delete a cron job we use the crontab command:
List crontab: crontab -l
Edit crontab: crontab -e
Remove crontab: crontab -r (this deletes all cron jobs)
So, if you want to add a cronjob, you can use the command crontab -e. if it's your first time running this command, it may prompt you to choose your preferred text editor, as shown below:
user@debian:~$ crontab -e no crontab for user - using an empty one Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/vim.tiny Choose 1-3 [1]:
Then, insert your cron job into the file and save it.
Cron jobs are useful for automating tasks like making backups, I use them myself for this website. You can also create scripts to clean up your server or remove unwanted files on a weekly basis.
I hope you found this helpful. Thank you for reading!
Good luck!
Comments