Skip to main content

Module 4: Process Management

Lesson 43: Cron Command

In this lesson, you'll learn how to use the cron command and crontab to schedule and run Linux tasks automatically at regular intervals.

Let's discuss the popular crontab command to schedule and run Linux tasks in the background automatically at regular intervals.

The users can automate Linux system backup, schedule updates, and synchronization of files, and many more using the Cron daemon, which is used to run scheduled tasks from the command line.

cron wakes up every minute and checks scheduled tasks in Crontab (CRON TABle) - a table where we can schedule such kinds of repeated tasks.

Tips: Each user can have their own crontab to create, modify, and delete tasks. By default, cron is enabled for users. However, we can restrict users by adding an entry in the /etc/cron.deny file.

Crontab Syntax

The Crontab file consists of commands per line and has six fields, separated either by space or tab. The first five fields represent the time to run tasks, and the last field is for the command.

# crontab -e
* * * * * /path/to/command
β”‚ β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚ └── Day of Week   (0-6 or Sun-Sat)
β”‚ β”‚ β”‚ └──── Month         (1-12 or Jan-Dec)
β”‚ β”‚ └────── Day of Month  (1-31)
β”‚ └──────── Hour          (0-23)
└────────── Minute        (0-59)

Field descriptions:

  • Minute - holds values between 0-59
  • Hour - holds values between 0-23
  • Day of Month - holds values between 1-31
  • Month of the Year - holds values between 1-12 or Jan-Dec (you can use the first three letters of each month's name, e.g. Jan or Jun)
  • Day of Week - holds values between 0-6 or Sun-Sat (you can also use the first three letters of each day's name, e.g. Sun or Wed)
  • Command - the /path/to/command or script you want to schedule

crontab Command Options

Option Description
-l List current user's crontab entries
-e Edit the current user's crontab
-r Remove the current user's crontab
-i Prompt for confirmation before removing crontab
-u USER Specify the user whose crontab to manage (root only)

1. List Crontab Entries

List or manage the task with the crontab command with the -l option for the current user.

# crontab -l
00 10 * * * /bin/ls >/ls.txt

2. Edit Crontab Entries

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’