Linux 101: How to copy files and directories from the command line

Linux 101: How to use cron


Continuing with his Linux 101 collection, Jack Wallen introduces you to the fundamentals of task scheduling with cron.

Graphic: Pixabay

For the admins who are new to Linux, I want to introduce you to the cron resource. What is cron? Basically said, cron enables you to create scheduled employment on a Linux procedure. Say, for occasion, you have a backup script, known as backup.sh. You have put that script in /usr/community/bin, so it can be executed globally and you want to make positive the backup transpires at possibly a particular time of working day or consistently on a particular working day of the 7 days. 

How do you do this? You invoke cron. 

To use this, you insert conjobs to your user’s crontab file. Log on to your Linux server and problem the command:  

crontab -l

This will record out all present cron work. To generate a new cron career, you edit the crontab file. To do this, situation the command: 

crontab -e

You would then include a line at the base of that file to plan the jogging of your backup script. This is where by it gets a bit difficult. The 1st segment of the line is in which you declare when the work is to run. At the beginning of that line there are 5 slots for time, which are (from left to proper): Minutes (-59), hrs (-23), day of month (1-31), thirty day period (1-12), day of week (-6, whilst you can use Sunday, Monday, Tuesday, and so forth., and Sunday can be represented by , 7, or Sunday). 

Let us say you want that backup job to run each and every Sunday at 11pm. That entry could be 23 * * . A star indicates the position is to materialize each and every iteration. In this scenario we’ve indicated the occupation must come about Sunday at 11pm, just about every week and each and every thirty day period. The rest of this line would consist of the explicit route to the executable, so /usr/area/bin/backup.sh. 

Our total line would be 23 * * /usr/community/bin/backup.sh. Conserve the crontab file with the Ctrl+X combination (if nano is your editor of choice), and the position is scheduled. You could possibly want to make sure your occupation is shown with the crontab -l command. 

Congratulations, you have just scheduled your to start with cron position. This need to be just adequate to get you likely with this potent Linux scheduling instrument.

Subscribe to TechRepublic’s How To Make Tech Perform on YouTube for all the most up-to-date tech advice for business enterprise professionals from Jack Wallen.

Also see



Supply website link