Cron in Linux

The cron in Linux is the same as the Time Schedule in Windows and has the ability to set the execution of commands at the specified time. In this article, we will install the cron in Linux and then we will get to know its command.

Cron in Linux is a scheduling system for executing scripts and commands that will act like the Time Schedule in Microsoft Windows.

Cron in Linux

With Cron, known as the Crontab command in Linux, you will be able to add commands under a shell script or as normal, and request execution at the desired time.

The Crontab tool is now available by default on most Linux distributions, but it may not be installed by default with minimal versions, etc.

How to install cron in RHEH / CentOS Linux

To install the crontab tool in RHEL and Centos and other distributions based on these two Linux versions run the following command:

yum install -y cronie
How to install cron in Ubuntu / Debian Linux

In Ubuntu and Debian and other distributions based on them, you can install the crontab tool with the following command:

apt-get install –y cron

At this point, when you install the cron, you can work with crontab commands.

How to work with crontab commands in Linux

In this article, we want to teach you basic crontab commands and in the other article, we will teach you how to work with

  1. Cronview preconfigured Crons in Linux

To view all of the jobs configured in cron, you can use the “-l” flag. run the following command:

crontab -l

2. Add a job in cron

To add a job or new jobs in cron or single delete them you can use the “-e” flag after the command to do your operation as an editor.

crontab -e

3. Delete all of the predefined jobs in cron 

You can delete jobs in the cron by using the “-r” flag.

Note: remember running the following command, delete all of the predefined jobs in cron.

crontab -r

Note: if you want to receive a confirmation for deleting you should run the following command:

4. View preconfigured jobs in a specific user’s cron in Linux

For doing this option in crontab you can use the “-u” flag.

You can use your user instead of orcacore.

The above command will show you all of the preconfigured jobs in orcacore’s cron file.

Note: you can add a job for another user easily. for doing this you just use the “-e” flag instead of “-l”.

Conclusion

Here are the introduction and installation of the cron in Linux are finished. and you can configure and add jobs in cron.

In upcoming articles, we will teach you how to work with cron with examples.

Hope you enjoy this article in OrcaCore about cron in Linux.

Leave a Comment

Scroll to Top