How to Setup Cron Job in Linux | Hostbillo 

Technically, a cron or cron job is a standard inbuilt Linux utility responsible for running the process and task on your system. All these tasks run at their specific scheduled time. Additionally, cron reads the crontab that is basically known as cron tables for all the commands and scripts already predefined in the Linux terminal. Linux is an open-source platform widely used to run the software, scripting language programs, and real-life-based applications. 

You can configure the Cron job if you want to run scripts and commands on your own or for other users. For that, you need to follow the proper cron job syntax to execute your code successfully in Linux. 

Through this guide, you’ll know how to setup cron Job in Linux, along with examples. If you want to do the process yourself, then read the guide carefully. Let’s get started!

What do you need to Setup a Cron Job in Linux?

Following are the basic elements that you require to setup a Cron Job manually in Linux:

  • Linux-based System
  • Access to Command Line (Ctrl–Alt–T )
  • Access to Terminal Window (Ctrl–Alt–F2)
  • A user account with root access to execute configurations

-The primary Crontab Syntax you can use for Linux

Cron is a system that helps Linux users to execute, run, and schedule the commands for configuration files. In this process, the cron daemon follows the specific code pattern called syntax to interpret the lines of commands in the crontab configuration tables.

To setup a proper cron job, you need to comprehend the basic elements used in building the syntax. 

A typical line in crontab looks like this:

a b c d e /directory/command output

in which, 

a b c d e = Specify the time/date, recurrence of the job.

Directory = Specify the location

Command = the script file you want to run

Output(Optional) = notify the user for job completion.

#1.  Cron job Time Format

In the command, space separates each position for a specific value.

First, five fields in the command impersonate the numbers that decide when and how often the command executes and runs on your Linux operating system. 

In the below-mentioned table, you’ll find all the possible values for the fields, and their syntax with the genuine examples:

FieldPossible ValuesSyntax Description
Minute0 – 597 * * * * Cron job is initiated, when your system clock shows minute’s position at 7
Hour0 – 230 7 * * *Cron job is initiated when your system clock shows 7 am. (7 pm = 19)
Day0 – 310 0 7 * * Cron job runs 7 days every month
Month0 = none,  12 = December0 0 0 7 *Cron job runs only in July month
Day of the Week0 = Sunday,  7 = Sunday0 0 * * 7 Job runs only on Sundays
Cron job Time Format

#2. Command to Execute

Command to Execute represents the accurate directory and exact script or command filename that you want the cron to run.

Let’s understand this with an example:


In this example, the command represents the system root directory and runs script in the backend exactly at 1:00 am every day. 

Command to Execute
Command to Execute

#3. Output (Optional)

Email is the best way to keep tracking your task. However, while running the task, cron sends the email to the crontab file owner. You might not realize it, but minor tasks can fill up your inbox very quickly. So, just keep the important ones and delete the rest of the emails.

This feature is optional in Cron Job for Linux. You can prevent it by disabling the output emails. 

In order to turn off Email Output, follow these steps: 

Add string >/dev/null 2>&1, after time and command field.

* * * * * directory/command >/dev/null 2>&1

#4. Using Operators (Optional)

For high-speed, cron jobs use some operators and characters. Operators are the special characters that perform specific operations and functions among the given values in the cron field. So, here we have mentioned the special operator, a cron job employed to perform operations. Check out the table:

Operator NameOperator SymbolFunction
Asterisk*Ensure task running 24*7 months, day, week
Comma,Separate Individual Values
DashIndicates a Range of Values
Forward-Slash/Divide value into two steps(Ex:7/8)

With the basic concepts, it’s now easy to comprehend the process of setting up a cron job in Linux.

Know the Steps to Setup a Cron Job

In this section, you’ll get to know how you can easily create a cron job in Linux. Also, you may see the syntax to quickly configure the cron job in Linux. You need to follow the instructions carefully:

  • First, open the Cron job with the text editor
  • Enter the syntax for the command you want to execute or run
  • Hit enter to see the output on your terminal window

You’ll get to know which syntax works well to edit the crontab files for a single user and different users. 

Step1: Edit the Crontab File

Steps for opening the Crontab configuration file:  

  • Open Terminal Windows
  • Type Command
crontab -e
  • Add numbers for task scheduling( number/line )
  • Save the File


Your code is then automatically read and executed by the cron daemon.

Note: To modify or change the code, you do not need to restart from scratch.

 Edit the Crontab File
 Edit the Crontab File

Step2: Edit crontab for a Different User

In step one, you have to run and edit the code for a single(own) user. Alternatively, you can edit the crontab for another user by typing the following command:

crontab –u other_username –e
Edit crontab for a Different User

-Cron Job Examples

When Specifying the jobs, use 

“*” =  Specify All Values

 Using this command in the fields, run all values:


* 1 0 * 3 /root/

Even though this command ensures your program runs at 1 am. But it runs when the first of the month (0) falls on a Tuesday (3). 

If you change it to:

0 1 1 * * /root/ *// Command runs at 1:00 am on the 1st day of every month. 

To describe it more effectively, we have mentioned the basic commands using /root/ file in the below-given table:

Run Cron Job  Command
Every Minutes* * * * * /root/
Every 30 Minutes30 * * * * /root/
Every 1 Hour0 * * * */root/
Every Day at Midnight0 0 * * * /root/
2 am Every Day0 2 * * * /root/
Every 1st of the Month0 0 1 * * /root/
Every 15th of the Month0 0 15 * * /root/
December 1st – Midnight0 0 0 12 * /root/
Saturday at Midnight0 0 * * 6 /root/

-Using Special Characters

  • Forward Slash(/): Use a slash to divide the time string. 

To run a backup every 10 Minutes use 

*/10 * * * *

/10 counts and repeats every 10th minute.

Using Special Characters
  • Asterisk(*): Means all value
  • Dash (-):  To specify a range

Ex: To run the code every weekday at 4 am

0 4 * * 1-5 /root/

Note: 1-5 specifies Monday – Friday.

Using Special Characters
  • Comma(,): specify individual instances
0 4 * * 2,4 /root/

This code runs every Tuesday and Thursday at “4 am”

Using Special Characters

You can combine some Wildcards. Use the following command to run every next day at 37 minutes past the hour.

37 1-23/2 * * * /root/


1-23 = Hour Range

/2 = Interval to every other hour.

-List Existing Cron Jobs

If you want to list all cron jobs in your system without opening the cron job configurations file. 

  • Open the terminal window 
  • Type the command
“crontab -1”
  • Hit on Enter
List Existing Cron Jobs

Also Read: Clear RAM Memory Cache, Buffer, and Swap Space on Linux

In Conclusion

Now you have sound Knowledge and enough understanding of how to use the cron job or daemon to schedule processes and tasks in your Linux-based system. Use the proper syntax and examples shown in this guide to create and run the file successfully. Additionally, you can expand the task in the cron job for Linux using special operators and characters. It helps you in automating most of your ordinary tasks.

Arpit Saini

He is the Chief Technology Officer at Hostbillo Hosting Solution and also follows a passion to break complex tech topics into practical and easy-to-understand articles. He loves to write about Web Hosting, Software, Virtualization, Cloud Computing, and much more.

Leave a Reply

Your email address will not be published. Required fields are marked *