问题描述:

In crontab does the Day of the Week field run from 0 - 6 or 1 -7?

I am seeing conflicting information on this. wikipedia states 0-6 and other sites I have seen are 1-7.

Also what would be the implication or either using 0 or 7 incorrectly? i.e. would the cron still run?

网友答案:

0 and 7 both stand for Sunday, you can use the one you want, so writing 0-6 or 1-7 has the same result (see comments in code below for a better example).

The numbers from 1 to 6 are fixed to Monday, ..., Saturday.

Graphically:

 ┌────────── minute (0 - 59)
 │ ┌──────── hour (0 - 23)
 │ │ ┌────── day of month (1 - 31)
 │ │ │ ┌──── month (1 - 12)
 │ │ │ │ ┌── day of week (0 - 6 => Sunday - Saturday, or
 │ │ │ │ │                1 - 7 => Monday - Sunday)
 ↓ ↓ ↓ ↓ ↓
 * * * * * command to be executed

Also, as suggested by @Henrik, it is possible to replace numbers by shortened name of days, such as MON, THU, etc.

Finally, if you want to specify day by day, you can separate days with commas, for example SUN,MON,THU will exectute the command only on sundays, mondays on thursdays.

More informations on Wikipedia.

网友答案:

According to Cyril Bouthors answer here is a list of the English abbreviated day of the week, which can be used in place of numbers:

 0 -> Sun

 1 -> Mon
 2 -> Tue
 3 -> Wed
 4 -> Thu
 5 -> Fri
 6 -> Sat

 7 -> Sun

Having two numbers for Sunday (0 and 7) can be useful for writing weekday ranges starting with 0 or ending with 7.

Examples of Number or Abbreviation Use

The next four examples will do all the same and execute a command every Friday, Saturday, and Sunday at 9.15 o'clock:

15 09 * * 5,6,0             command
15 09 * * 5,6,7             command
15 09 * * 5-7               command
15 09 * * Fri,Sat,Sun       command
网友答案:

You can also use day names like Mon for Monday, Tue for Tuesday, etc. It's more human friendly.

相关阅读:
Top