How to Schedule Tasks on Ubuntu 20.04 Using Crontab

Cron and Crontab on Ubuntu

Sometimes you don’t want a process to run at a default time set by the operating system, but you want to set the time for a process to run yourself. To do this, we use the cron daemon in Ubuntu, which works in the same way as the task scheduler in Windows. With the cron daemon, you can specify the time at which a process, such as a maintenance or a backup job, should be executed. This way, you can automate these tasks to run later without manual intervention. This article explains how you can do this with Crontab in Ubuntu.

Scheduling of Tasks in Ubuntu Using Crontab

For doing this, you need to proceed as follows:

Launch terminal by pressing Ctrl+ T or clicking on the terminal icon located on the taskbar or searching for terminal in the search window and pressing enter. The newly opened terminal window is shown below:

Now type the command crontab -e in the terminal and press enter to open the crontab file. This command is shown below:

Edit crontab by using the crontab-e command

As soon as you will press enter, the terminal will ask you to select an editor to open this file. Press 2 and then press enter to select nano editor because it is always good to open system files with nano editor.

crontab opened in nano editor

Select nano editor

The moment you will press enter, you will see that your terminal has changed itself into the nano editor window and your crontab file has opened in this editor. It is shown below:

Crontab in edit mode

You can scroll through this file by making use of the up and down arrow keys. All the lines written in this file that start with a ‘#’ represent a comment. If you want to add a new task to get scheduled at your specified time, then you must write it without a hash. For example, if you want to run a backup of all your user accounts every week at 5 a.m, then you should type the command:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

This is shown below:

How to set up a backup cronjob

Once you have finished adding your tasks, just press Ctrl+ O to save your crontab file in nano editor. It will show the modified status as top right corner and will ask you for a file name to write. Just press enter to select default. It is given below:

Save and activate the cronjob

After pressing enter, you will be returned to your regular nano editor window. Now to exit from nano editor after saving your file, just press Ctrl+ X.

As soon as your nano editor will close, you will be directed to your original terminal window. Here you will see the “crontab: installing new crontab” message, which is an indication to tell that your crontab file was saved successfully. This message is shown in the image below:

Crontab created successfully

Once you are done with this, now all your user accounts will experience a backup every week at 5 a.m.


Through the method explained above, you can schedule any system-related tasks at the time of your own choice. These changes will be saved forever until you modify this file again. This kind of automation reduces the burden of the user of doing everything manually. I hope this article was helpful.