Skip to content
Search

Cron

lastmod 2025-12-11created 2014-01-0734 edits

A daemon and its configuration for running specific jobs periodically and repeatedly at set times.

  • The cron system has cron settings used by the system by default; these are called the system cron.
  • The cron system also has user cron, where root or regular users set up and use their own cron settings.

Categories

Usage

To set a job schedule, enter the fields in the following order. (The separator is a space.)

  1. Minute: takes values 0-59.
  2. Hour: takes values 0-23.
  3. Day of month: takes values 1-31.
  4. Month: takes values 1-12.
  5. Day of week: takes values 0-7. Both 0 and 7 are Sunday. English names may also be used.
  6. Command

For example, to back up all user accounts using tar every Monday at 5 AM:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

The output of crontab jobs (including errors) is sent by email to the user who owns the crontab file. The mail file path is /var/mail/$USER.

  • * - means every value.
  • ? - means no specific value.
  • - - means a range. (e.g.) Monday through Wednesday is written MON-WED
  • , - runs only on specific values (e.g.) Mon, Wed, Fri: MON,WED,FRI
  • / - start time / interval (e.g.) every 5 minutes starting at minute 0: 0/5
  • L - in the day field, the last day; in the day-of-week field, the last day of the week (Saturday)
  • W - the nearest weekday (e.g.) 15W finds the weekday (Mon–Fri) nearest the 15th
  • # - expresses a given weekday of a given week (e.g.) 3#2 : Wednesday of the 2nd week
  • cron daemon file: /usr/sbin/crond
  • Start/stop/restart the cron daemon: /etc/rc.d/init.d/crond start/stop/restart
  • Check that crond is running: ps -ef | grep crond
  • cron configuration file: /etc/crontab
  • System cron configuration directories: /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly
  • User cron configuration files: /var/spool/cron/* 1
    • Location of user cron configuration files set with the crontab -e command: /var/spool/cron/crontabs/*
  • User cron configuration command: /usr/bin/crontab
  • Log file recording cron runs: /var/log/cron

Editing the user schedule

Edit the cron schedule using vim:

$ EDITOR=vim crontab -e

Checking the schedule

To see the currently configured schedule, check it as follows.

$ crontab -l

Setting the time

Open the editor:

$ crontab -e

The syntax is as follows:

 *  *  *  *  *  <명령어>
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───────── 요일 (0 - 6) (0:일요일, 1:월요일, 2:화요일, …, 6:토요일, *:매일)
│ │ │ └───────── 월 (1 - 12) (*:매월)
│ │ └───────── 일 (1 - 31) (*:매일)
│ └───────── 시 (0 - 23)
└───────── 분 (0 - 59)

# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
0 0 * * *
Runs every day at midnight (00:00)
10 1 * * *
Runs every day at 1:10
0 1,12,18 * * *
Every day at 1:00, 12:00, and 18:00
0 0 1-10 * *
At midnight on the 1st through the 10th
* * * * *
Continuously, once every minute
*/10 * * * *
Continuously, once every 10 minutes
0 0 1-10,15 * *
Runs at midnight (00:00) on the 1st through the 10th and on the 15th of every month
0 0 * * 0
Every Sunday at midnight

See also

Favorite site

Online Tools

References


  1. Exists as a file named after the user account name ↩

  2. Superuser_linux-cron.pdf ↩

author Zer0 sitemap