📜  cron cheatsheat (1)

📅  最后修改于: 2023-12-03 15:30:07.346000             🧑  作者: Mango

Cron Cheatsheet

Cron is a time-based job scheduler in Unix-like operating systems used to execute tasks at specified intervals or times. Here's a cheatsheet to help you use cron effectively.

| Syntax | Explanation | |--------|-------------| | * * * * * | Execute command every minute | | 0 * * * * | Execute command every hour at minute 0 | | 0 0 * * * | Execute command every day at midnight | | 0 0 * * 0 | Execute command every Sunday at midnight | | 15 14 1 * * | Execute command on the 1st day of every month at 2:15 PM |

You can also use the following shortcuts:

  • @yearly or @annually - Execute command once a year at midnight on January 1st
  • @monthly - Execute command once a month at midnight on the first day of the month
  • @weekly - Execute command once a week at midnight on Sunday
  • @daily or @midnight - Execute command once a day at midnight
  • @hourly - Execute command once an hour at the beginning of the hour

To edit the crontab file, use the following command:

crontab -e

To list the current crontab entries, use the following command:

crontab -l

To remove all of your crontab entries, use the following command:

crontab -r

Each line in the crontab file consists of six fields:

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of the week (0 - 7) (Sunday is both 0 and 7)
| | | ------- Month (1 - 12)
| | --------- Day of the month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Remember to escape special characters like % with a backslash (\).

With this cheatsheet, you should be able to easily schedule tasks using cron in your Unix-like system!