Ubuntu Crontab: How it Works and Commands You need

Here the commands you need to work with crontab. Explained with sample data and these work in Ubuntu.

IN THIS PAGE

  1. What is Crontab
  2. How to List and Edit crontab
    1. List command
    2. Edit command
  3. How to add job to crontab
  4. How to Backup and Replace crontab
    1. Backup command
    2. Replace command
  5. What is Timezone in Crontab

What is Crontab

Crontab in Ubuntu automates shell scripts. Here is my earlier post on this topic. In Ubuntu or any other Linux operating system, the crontab allows for edits only to root users. The sudo users usually are root users.

How to List and Edit crontab

Here are four ridiculously useful commands that you can use while working with Crontab. These are list, edit, backup, and replace commands.

List command

You can view jobs with the list command.

$sudo crontab -l # browse

Edit command

You can edit the Crontab with the edit command.

$sudo crontab -e #edit

How to add job to crontab

To show how to add a cron job, I have added a simple job, which creates a directory at the specified time.

Crontab in Ubuntu The Top Features
Crontab in Ubuntu The Top Features

Example cron job

The job runs at 15 minutes, at 20 hours, on 30th, July (7th ), and Saturday, execute command is mkdir srini. A directory of srini creates after running this crontab command.

How to Backup and Replace crontab

Backup command

Here is a command you can use to take the backup of Crontab.

Replace command

Taking backup is the best practice before making changes to the Crontab. The following command replaces the current set of jobs with the jobs in the file crontab.new:

$ crontab -r > crontab.new

What is Timezone in Crontab

Please note that Crontab triggers scripts according to your operating system’s Timezone.

Related

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.