What is cron?

On Linux and similar systems, the mechanism (and its daemon) that runs commands automatically at set times or intervals. Each line of the settings edited with crontab -e is written as "minute hour day-of-month month day-of-week command", and "30 2 * * 1 command" means 2:30 every Monday (for the day of week, 0 is Sunday, and in many implementations so is 7). * means every value, */5 every 5 and 1-5 a range. Commands run from cron work with a more limited set of environment variables than a login session, so care is needed with paths and with recording output. On systems with systemd, systemd timers can do the same.

Japanese name: cron

cron appears in 1 practice question across 1 topic, including Linux and Command-Line Basics.

Field: Linux and Command-Line Basics

Try it: questions about cron

The line "30 2 * * 1 /home/alice/backup.sh" was registered in cron. Which of the following is when backup.sh is run?

  1. AAt 2:30 on the 1st of every month
  2. BAt 2:30 every Monday
  3. CAt 2:30 every Sunday
Show answer and explanation

Answer: B. At 2:30 every Monday

In a cron configuration (crontab), each line starts with five fields that are, from the left, "minute, hour, day of month, month, day of week", followed by the command to run. In this line the minute is 30, the hour 2, the day of month and month * (every), and the day of week 1, so it runs at 2:30 every Monday. For the day of week, 0 is Sunday and 1 is Monday, and in many implementations 7 also means Sunday. Commands run from cron work with a limited set of environment variables, unlike a login session, so care is needed, such as writing commands in scripts with absolute paths.

cron in the explanations

Questions that mention cron (1)

  1. The line "30 2 * * 1 /home/alice/backup.sh" was registered in cron. Which of the following is when backup.sh is run?

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

Environment variable File permissions Git grep Hard link I/O redirection inode Pipe (|) Regular expression Shell

Back to the glossary