Cron in Linux — Crontab Syntax, Examples and Calculator
Cron expression calculator
minute hour day_of_month month day_of_week. The description and the next runs are calculated automatically.Cron is the standard task scheduler in Linux: it runs commands on a schedule (every minute, hour, day and so on). The schedule is defined by five fields in a crontab file. Here is the syntax plus ready-made examples.
Crontab syntax
Every job line consists of five time fields and a command:
* * * * * command
│ │ │ │ │
│ │ │ │ └─ day of week (0–7, where 0 and 7 are Sunday)
│ │ │ └─── month (1–12)
│ │ └───── day of month (1–31)
│ └─────── hour (0–23)
└───────── minute (0–59)
Special characters:
*— any value;*/5— every 5 units (every 5 minutes, for example);1,15— a list of values;9-18— a range.
How to edit the crontab
To open your own job list for editing:
crontab -e
To view the current jobs:
crontab -l
Changes apply automatically once you save — nothing needs restarting.
Schedule examples
| Schedule | Line | When it runs |
|---|---|---|
| Every minute | * * * * * |
every minute |
| Every 5 minutes | */5 * * * * |
0, 5, 10… |
| Every hour | 0 * * * * |
on the hour |
| Daily at 3:30 | 30 3 * * * |
once a day |
| Weekdays at 9:00 | 0 9 * * 1-5 |
Mon–Fri |
| On the 1st of the month | 0 0 1 * * |
monthly |
Ready-made job examples:
# Database backup every day at 2:30 a.m.
30 2 * * * /usr/local/bin/backup.sh
# Clean up temporary files every Sunday at 4:00
0 4 * * 0 find /tmp -type f -mtime +7 -delete
# Check the website every 10 minutes
*/10 * * * * curl -s https://example.com > /dev/null
Special strings
Instead of five fields you can use convenient aliases:
@reboot /path/script.sh # when the server boots
@daily /path/script.sh # once a day at midnight
@hourly /path/script.sh # once an hour
@weekly /path/script.sh # once a week
Logging and debugging
Cron does not print anything to your screen. To see what is happening, redirect the output to a file:
0 2 * * * /path/backup.sh >> /var/log/backup.log 2>&1
2>&1 sends both errors and normal output to the same log.
To check that cron runs jobs at all, look at the system log:
grep CRON /var/log/syslog
Common reasons a job does not run
- Relative paths. Cron runs in a stripped-down environment. Use full paths to commands and files (
/usr/bin/php, notphp). - Environment variables.
PATHinside cron is minimal. Set the variables you need at the top of the crontab or inside the script. - No execute permission. Make the script executable:
chmod +x /path/script.sh. - Missing newline. The last line of a crontab must end with a newline.
Frequently asked questions
How does a user crontab differ from the system one?
crontab -e edits the current user’s jobs. System jobs live in /etc/crontab and /etc/cron.d/, where you also specify the user the command runs as.
Why does a job work manually but not from cron?
Usually because of the environment: cron does not know your PATH and variables. Use absolute paths and set the variables explicitly in the script.
How do I run a job as root?
Edit root’s crontab with sudo crontab -e, or add the job to /etc/cron.d/ with the user set to root.
Is there an alternative to cron? Yes, systemd timers are a more flexible and better-logged alternative. But cron is simpler and present on virtually any server, so it remains the standard.
Summary
Cron covers almost any scheduled automation: backups, cleanups, checks. Learn the five syntax fields, always use absolute paths and log the output — and your jobs will run reliably.
Need a server for your own tasks and scripts? Take a Linux VPS, order VPS hosting, or order Server administration.