Site icon LinuxCommands.site

Linux crontab format and crontab examples

Linux crontab command is a command used to periodically execute programs. It uses the job scheduler cron to execute tasks.

This article shares the Linux crontab command format, crontab examples, syntax, related commands, and how to use crontab commands from it.

crontab format


 +---------------- minute (0 - 59)
 |  +------------- hour (0 - 23)
 |  |  +---------- day of month (1 - 31)
 |  |  |  +------- month (1 - 12)
 |  |  |  |  +---- day of week (0 - 6) (Sunday=0)
 |  |  |  |  |
 *  *  *  *  *  command to be executed

Crontab command consists of: time + action, where time is divided into minutes, hours, days, months, and weeks.

The time operators are:

crontab options

crontab — maintain crontab files for individual users

crontab examples

1. crontab every minute execute

In the following crontab example, the command “myCommand” is executed every minute.

* * * * * myCommand

2. crontab every five minutes execute

In the following crontab example, the command “myCommand” is executed every 5 minutes.

*/5 * * * * myCommand

3. Execute on 10th minute and 40th minute on Sundays from 5 am to 7 am

In the following crontab example, it means that the command “myCommand” will be executed on the 10th and 40th minutes of every Sunday from 5am to 7am

10,40 5-7 * * 0 myCommand

4. 21:30 every night

30 21 * * * myCommand

5. crontab every two hours execute

In the following crontab example, the command “myCommand” is executed every two hours.

* */2 * * * myCommand

OK.

Linux crontab format, syntax and common examples of crontab are introduced. Have you got it?

Exit mobile version