How to use the crontab command under Linux: sudo crontab-l

Source: Internet
Author: User

Cron is the next program in the Linux system that automatically executes a specified task.

The cron service is a built-in service for Linux, but it does not boot automatically. You can start and stop the service with the following command:

Linux Code
  1. /sbin/service Crond Start
  2. /sbin/service Crond Stop
  3. /sbin/service Crond Restart
  4. /sbin/service Crond Reload

The above 1-4 lines start, stop, restart the service, and reload the configuration, respectively.

To set cron to start automatically when booting, in the/etc/rc.d/rc.local script can be added /sbin/service crond start .

View, delete, modify

Cron saves the command line in the crontab (cron table) file, which is usually in the/etc directory. Each system user can have their own crontab (under/var/spool/cron/).

  • File uses the contents of the file as a cron service configuration for a user, and the contents are copied to the Cron service's configuration file
  • -U sets a user's cron service configuration, which is typically required by the root user when executing this command
  • -l lists a user cron service configuration
  • -R Delete a user's cron service configuration
  • -e Edit a user's cron service configuration, when specified crontab does not exist, new, will use VI to open the configuration file for editing save after the exit, file syntax see after
  • Crontab–v show The last edit time (available on some operating systems only)
Example: sudo crontab-lGrammareach line represents an instruction, which represents a scheduled task, each line consists of six parts separated by a space, the first 5 represents the time of the scheduled task execution, and the remainder is the command to be executed by the timed task, in the following format:

minute   Hour Sun Moon Week command
minute  hour  day  month  dayofweek  Command

    • minute the first few minutes of each hour to perform the task, 0-59
    • command specifies the program to execute

The first five items above can be used with the following four special symbols:

  • * Indicates all values, such as the first bit using * indicates every minute
  • /denotes each, as the first bit uses */5 to denote every 5 minutes
  • -Represents a range of values, as the second bit uses 2-4 to indicate 2 to 4 points
  • That represents a discrete number of values, such as the 2nd bit using 6,8 to represent 6 points and 8 points
  • Specify "step": 8-14/2 for 8,10,12,14
  • Specify a list: such as "1,2,3,4″," 0-4,8-12″

In the six fields of each row, except that the command is a field that must be specified each time, the other fields are optional fields, which can be determined visually. For a field that is not specified, "*" is used to fill its position.

Example: Execute the following command every 10 minutes



  1.     5        *      *     *      ls     Specify the Daily  5 : Span class= "number" style= "Color:rgb (192,0,0)" >30   execute ls command   
  2.     7        8        *     *     ls     Specify monthly 8 " 7 : 30 performs the ls command   
  3.     5        8        6      *      ls     Specify annual 6 month 8 day 5 : 30 execute ls command   
  4. 6 * * 0 ls specified per Sunday of 6: Execute ls command [note:0 means Sunday, 1 said the week 1, and so on, can also be expressed in English, Sun said Sunday, Mon said Monday and so on. ]



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

How to use the crontab command under Linux: sudo crontab-l

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.