cron
Learn how to schedule and automate tasks in Linux using cron jobs.
Commands
Common commands for checking, editing and managing cron jobs.
Check cron service
Ensure that the cron service is installed and running.
systemctl status cronEdit user crontab
Open the crontab editor for the current user.
crontab -eList scheduled jobs
View existing cron jobs for the current user.
crontab -lRemove all jobs
Clear the user’s crontab.
crontab -rAutomate with system-wide crontab
System jobs can be placed in /etc/crontab
sudo nano /etc/crontabSyntax
Cron jobs use a five-field time format followed by the command to execute.
# ┌───────────── minute (0–59)# │ ┌───────────── hour (0–23)# │ │ ┌───────────── day of month (1–31)# │ │ │ ┌───────────── month (1–12)# │ │ │ │ ┌───────────── day of week (0–6, Sun=0)# │ │ │ │ │# │ │ │ │ │# * * * * * command_to_executeExamples
Common examples of scheduling tasks with cron.
Run script every day at midnight
0 0 * * * /home/username/backup.shRun a task every 15 minutes
*/15 * * * * /usr/bin/python3 /home/username/task.pyWeekly cleanup task
0 3 * * 0 root /usr/bin/apt autoremove -y