73

The first noncomment line in a legacy crontab file begins with five asterisks:

* * * * * ([a_command]) >/dev/null 2>&1

The authors are gone, so I do not know their intent. What does all-wildcards mean to (Solaris 8) cron? The betting here is either run once, run continuously, or run never, which is unfortunately broad.

If you are wondering about the comment line preceding this, it is "Do not delete."

Note: This cron file is working. This question is not a duplicate of a question about broken cron files or cron files which require troubleshooting.

Avery Payne
  • 14,326
  • 1
  • 48
  • 87
Thomas L Holaday
  • 1,253
  • 4
  • 16
  • 19
  • 4
    Something else to note, since it tripped me up severely at work recently: the >/dev/null 2>&1 section feeds all output from STDOUT and STDERR to /dev/null. The reason this is done: If you don't, then output from the program called in crontab will be mailed to the local mailbox of the user. Before I knew this I filled up a hard drive on a production server from a script running every two minutes. – Luke has no name Jul 24 '10 at 07:16
  • Thanks, Luke has no name; I had mis-attributed it to over-fussiness. – Thomas L Holaday Aug 18 '10 at 19:36
  • It looks like it qualifies to me. The answer explains how crontab works, and as it explains, this would run once every minute. The marking as duplicate is not meant to disparage your question, but to collect the commonly asked questions about cron, and their answers, in a single place. – Michael Hampton Jun 11 '14 at 00:20

3 Answers3

64

Every minute of every day of every week of every month, that command runs.

man 5 crontab has the documentation of this. If you just type man crontab, you get the documentation for the crontab command. What you want is section 5 of the manual pages which covers system configuration files including the /etc/crontab file. For future reference, the sections are described in man man:

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous  (including  macro  packages and conven‐
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]
jokerdino
  • 391
  • 3
  • 12
Luke has no name
  • 1,219
  • 1
  • 12
  • 14
  • That's the literal meaning; I was worried that it might be a special case. Thanks for the reassurance. – Thomas L Holaday Jul 20 '10 at 21:19
  • 13
    +1 for the answer, -1 for the `man cron` comment. `man` pages are notoriously hard to read and understand for the beginner - that's why people come here, to have the `man` pages explained to them. – Mark Henderson Jul 20 '10 at 21:25
  • 4
    Totally, because it should have been `man 5 crontab`. That manpage is more specific and very easy to understand. See: http://linux.die.net/man/5/crontab – Warner Jul 20 '10 at 21:34
  • `man 5 crontab` is over 9000 times more useful in this case. – ThatGraemeGuy Jul 20 '10 at 21:38
  • 6
    That's fine, provided the user is aware that the 5 is even relevant. Most new or part time Linux users don't know what number, if any, to use to access man pages. – John Gardeniers Jul 20 '10 at 21:43
  • 3
    @John, to prove your point, as someone who only dips their toe into *nix when I need to restart the occasional apache server, I was not even aware you could do a `man 5` and I have no idea what would happen if I did... – Mark Henderson Jul 21 '10 at 03:19
  • @Farseeker, neither was I :) – John Gardeniers Jul 21 '10 at 03:33
  • @Farseeker, "man man". :) – Luke has no name Jul 21 '10 at 19:43
  • +1 for the `man man` list! – Torben Gundtofte-Bruun Aug 11 '10 at 14:27
  • 1
    -1 for the man cron also. I just googled the answer since it is faster than digging through the RAW man page. I also was worried it would be a special meaning that I would miss. Think about who will read your answer, we're not reading it to learn about the documentation but to know an answer to a question. – Aki Oct 01 '13 at 17:01
  • Learning about documentation gives you answers to all your questions, and without internet to boot. While I agree that simply pointing the man pages isn't helpful; @Lukehasnoname also answered the question. – DylanYoung Aug 16 '16 at 18:37
  • I think it was answered perfectly by answering the question AND referring to the relevant section in the man page. Quick answer, and a resource for where to go for more detail. Plus, helpful for future similar queries. – redfox05 May 15 '19 at 17:33
  • Actually, the comment about man 5 whatever was very useful. – conjectures Jul 06 '20 at 10:18
51

* = always. It is a wildcard for every part of the cron schedule expression.

So * * * * * means every minute of every hour of every day of every month and every day of the week.

 * * * * *  command to execute
 ┬ ┬ ┬ ┬ ┬
 │ │ │ │ │
 │ │ │ │ │
 │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 │ │ │ └────────── month (1 - 12)
 │ │ └─────────────── day of month (1 - 31)
 │ └──────────────────── hour (0 - 23)
 └───────────────────────── min (0 - 59)

The nice drawing above is provided by wikipedia

An other example:

0 * * * * -this means the cron will run always when the minutes are 0 (so hourly)
0 1 * * * - this means the cron will run always at 1 o'clock.
* 1 * * * - this means the cron will run each minute when the hour is 1. So 1:00, 1:01, ...1:59.

Mohammad Faisal
  • 613
  • 5
  • 5
  • 1
    Man that really makes sense to me now. Thanks for the explanation. – Vishal Jul 28 '17 at 13:39
  • 1
    Isn't the sixth column for username as which to run the command? I've always wondered how does cron distinguish the command from the user, if there is space in between, like `* * * * * php /var/myscript.php` - how cron knows if `php` is part of command and not a username? – JustAMartin Nov 19 '17 at 00:08
  • 1
    @JustAMartin check this [answer](https://stackoverflow.com/a/22207714/725306). The cron jobs created with `crontab` command seems to be linked to the user and do not need the sixth column for user. – Mohammad Faisal Feb 12 '20 at 09:21
  • */2 in the first column will run every 2 mins. All kinds of possibilities I guess explained in the man page somewhere. – blissweb Jan 12 '22 at 08:24
11
First star = Minutes: 0-59
Second star = Hours: 0-23
Third star = Day of Month: 0 - 31
Fourth star = Month: 0 - 12
Fifth star = Day of Week: 0 - 6 (0 means sunday)

Say you want to run something every 1st of every month.

0 0 1 * * something.sh
Michael Burns
  • 288
  • 1
  • 5