System Administration

Cron Job Cheatsheet

Master cron job scheduling with comprehensive examples, special strings, crontab commands, and special characters reference for automating tasks on Linux systems.

Master cron job scheduling for automated tasks on your VPS. Looking for reliable hosting to run your scheduled tasks? Explore our top-rated VPS providers with proven uptime, or check our performance benchmarks to find the perfect match for your automation needs.

#cron #scheduling #linux #automation #sysadmin #crontab
Sign In to Download

Free account required

i

Cron Format

* * * * * command to be executed
Minute
0-59
Hour
0-23
Day
1-31
Month
1-12
Weekday
0-6 (Sun=0)

Practical Examples

* * * * *  /opt/backup.sh
Every minute
*/7 * * * *  /opt/ping.sh
Every 7 minutes
0 */6 * * *  /opt/emptytrash.sh
Empty trash every 6 hours
20 14 * * *  /opt/upgrade
Upgrade at 14:20 PM every day
5 9 * 4 *  /opt/upgrade
Upgrade at 09:05 AM in April
20 14 * * 7  /opt/update.sh
Update at 14:20 PM every Sunday
6 11 * * 3  /opt/upgrade.sh
Upgrade at 11:06 AM every Wednesday
0 22 * * 1-5  /opt/upgrade.sh
Upgrade at 22:00 PM from Monday to Friday
0 0 * * 2  /opt/upgrade.sh
Upgrade at midnight (00:00) every Tuesday
10 8 * * 4L  /opt/monitor.sh
Monitor at 08:10 AM on last Thursday of every month
15 0 * * 4#2  /opt/upgrade
Upgrade at 00:15 AM on second Thursday of every month
0 0 0 1 * *  /opt/backup.sh
Backup every 1st of month (monthly)
0 0 0 1 1 *  /opt/backup.sh
Backup every 1st of January (yearly)
5 12 * * 6  /opt/emptytrash.sh
Clear trash at 12:05 PM on Sunday
@reboot  /opt/backup.sh
Run backup at system reboot

Special Strings

@reboot

Execute once at system startup (non-standard)

@hourly

Execute once every hour, same as 0 * * * * (non-standard)

@daily

Execute once per day, same as 0 0 * * * (non-standard)

@midnight

Same as @daily (non-standard)

@weekly

Execute once every week, same as 0 0 * * 0 (non-standard)

@monthly

Execute once per month, same as 0 0 1 * * (non-standard)

@yearly

Execute once per year, same as 0 0 1 1 * (non-standard)

@annually

Same as @yearly (non-standard)

Crontab Commands

Edit or create a crontab file

$ crontab -e

Tip: Check our Linux commands cheatsheet for more text editor options.

Display the crontab file

$ crontab -l

Remove the crontab file

$ crontab -r

Display another user's crontab file

$ crontab -u username -l

Edit another user's crontab file

$ crontab -u username -e

Display last time you edited your crontab file

$ crontab -v

Special Characters

* Asterisk (*)

Represents all potential values in a field. For example, an asterisk in the Minute column means "every minute".

- Hyphen (-)

Used to determine a range of values. For example, write 1-5 in the Weekday field to schedule a task from Monday through Friday.

/ Slash (/)

Used to split a value. For instance, */5 in the Hours field signifies "every 5 hours".

, Comma (,)

Used to list numerous values. Writing 1,5 in the Day of the week field schedules the task to be executed every Monday and Friday.

L Last (L)

Used in the month and weekday fields. Writing 6L in the day-of-week field, for example, signifies "the last Saturday of the month".

W Weekday (W)

Used to get the closest weekday from a given time. For instance, entering 1W in the day-of-month field will execute the command on the following Monday (the 3rd).

# Hash (#)

Only valid in the Day-of-week field, followed by a number between 1 and 5. For example, 5#2 denotes "the second Friday" of a given month.

? Question mark (?)

Can be used instead of '*' in the Day of Month and Day of Week fields. Use this operator to enter "no specified value" for the "day of the month" and "day of the week" fields.

Automate Your VPS Tasks

Need reliable VPS hosting for your scheduled tasks? Check out our benchmarks to find providers with 99.9% uptime and optimal performance for your cron jobs.