Scheduling Task In Linux Using Crontab

Hello everyone In this article I am going to discuss a very useful feature of Linux — “Crontab”. It is used to schedule tasks. It is one of the most useful features for server administrators.

Some tasks are to be done again and again, like backups and updates. It becomes harder when you have more than one server to manage.

To solve this problem crontab comes into action. It will help you to run tasks in a time/date/month/hour that you specify.

So let us begin learning how you can use crontab and schedule your tasks.

Opening Crontab

To open crontab open your terminal and type

crontab -e

If you are using it for the first time than it will show you something like this –

Choose any text editor that you want. I prefer vim (2nd option), but if you are newbie Linux uses nano editor (1st option).

If your task requires admin privileges to execute the command you must open crontab using this command

sudo crontab -e

Note — crontab -e and sudo crontab -e both are representing a different file.

Basic Usage

Crontab has a particular syntax to declare any task to be scheduled.


* * * * * <command-to-be-executed> <arguments>

So in the above syntax every position in which * is present, represents something.

Here is the detail of what each position means in the above syntax.

In the syntax, some symbols are also used. These are:

  1. * – Represents Every
  2. , -Value List Separator
  3. - – Range Of Values
  4. /– Step Values


So let us have some examples –

Command to run a script every minute

* * * * *

The above command will run the backup script every minute.

Command to run a script at 00:00 every day

0 0 * * *

Command to run a script at 5 am every day

0 5* * *

Command to run the script every Sunday at 5 am

0 5 * * SUN

The above command can also be written as

0 5 * * 0

Command to run a script in weekdays

* * * * 1-5

The above command can also be written as

* * * * MON-FRI

Command to run the script on starting of every month

0 0 1 * *

Command to run the script on starting of last month of every year

0 0 1 12 *

Command to run script on 10:50 AM every day

50 10 * * *

Command to run the script after every 30 minutes

*/30 * * * *

So these are some examples that I have taken you to get an understanding of how to schedule a task using crontab.


So there above we have learned to write a task in crontab. There are some shortcuts that you can also use.

  1. @reboot — Run once, at startup
  2. @yearly — Run once a year
  3. @annually — Run once a year ( Same as @yearly )
  4. @monthly — Run once a month
  5. @weekly — Run once a week
  6. @daily — Run once a day
  7. @midnight — Run once a day in midnight ( Same as @daily )
  8. @hourly — Run once an hour




Some other commands

To list all the crontab jobs

crontab -l

To remove all crontab jobs

crontab -r

To enter crontab for a particular user

crontab -u <username> -e

Crontab Guru

You can also use CrontabGuru to generate cron command for you task. This is one of my favourite site to generate and check cron commands.

So this is all about crontab. I hope you have found this article useful. If you have any problem ask me in the comment section.


Leave a Reply

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