The crontab command and switches with example

Linux crontab and job scheduling

In Linux, we can not ignore the usages of cron. It’s command line utility and it helps to schedule tasks. Those tasks will execute periodically pas per the configuration. In this article I am just mentioning the basic operation of crontab command.

Crontab is the program used to install, remove or list the tables used to drive the cron daemon. Cronjobs are predefined jobs which are running periodically according to the settings we have done previously.


# crontab [-u user] [-l | -r | -e] [-i] [-s]

Important switches with example 

1, -u

Append the name of the user whose crontab is to be tweaked. If this option is not given, crontab examines “your” crontab, i.e., the crontab of the person executing the command. Note that su(8) can confuse crontab and that if you are running inside of su(8) you should always use the -u option for safety’s sake. The first form of this command is used to install a new crontab from some named file or standard input if the pseudo-filename “-” is given.

2, -l

Lists all jobs.


[[email protected] ~]# crontab -l
no crontab for root

For a user

[[email protected] ~]# crontab -u crybit -l
no crontab for crybit

3, -e

This option is for editing the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically.


[[email protected] ~]# crontab -e

For a user:

[[email protected] ~]# crontab -u crybit -e

4, -r

To remove current crontab. Do it carefuly, it will remove all cronjobs under the current user.


[[email protected] ~]# crontab -r
no crontab for root

For a user:

[[email protected] ~]# crontab -u crybit -r
no crontab for crybit

5, -i

This option modifies the -r option to prompt the user for a ’y/Y’ response before actually removing the crontab.


[[email protected] ~]# crontab -ir
crontab: really delete root's crontab? y
no crontab for root

For a user:

[[email protected] ~]# crontab -u crybit -ir
crontab: really delete crybit's crontab? y
no crontab for crybit

6, -s

It will append the current SELinux security context string as an MLS_LEVEL setting to the crontab file before editing / replacement occurs – see the documentation of MLS_LEVEL in crontab(5).


[[email protected] ~]# crontab -u crybit -es
no crontab for crybit - using an empty one
crontab: installing new crontab
[[email protected] ~]# crontab -u crybit -l

That’s it..!! 🙂

Related links:
list cronjobs running under a user
Examples of Job Scheduling Using Crontab

ls, head, tail, top, ps, find, crontab, groupdel, groupmems, groupmod, useradd , usermod , chgrp, chown

How to check the execution time of your script in cron?

Post navigation

Arunlal Ashok

Engineer at Endurance International Group. Linux lover.

Always happy for an open discussion! Write to arun (@) crybit (dot) com.

5 thoughts on “The crontab command and switches with example

Leave a Reply

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