Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to schedule a task to run on a regular basis and have heard that Cron is the way to do this.

How do I add Cron jobs in Ubuntu?

share|improve this question
up vote 329 down vote accepted

Put a shell script in one of these folders: /etc/cron.daily, /etc/cron.hourly, /etc/cron.monthly or /etc/cron.weekly.

If these are not enough for you you can add more specific tasks eg. twice a month or every 5 minutes or... go to the terminal and type:

crontab -e

this will open your personal crontab (cron configuration file), the first line in that file explains it all (don't you think)! In every line you can define one command to run, and the format is quite simple when you get the hang of it. So the structure is:

minute hour day-of-month month day-of-week command

For all the numbers you can use lists eg, 5,34,55 in the first field will mean run at 5 past 34 past and 55 past what ever hour is defined.

You can also use intervals, they are defined like this: */20 this example means every 20th and if in the minutes column this will be equivalent to 0,20,40
So to run a command every monday at 5:30 in afternoon:

30 17 * * 1 /path/to/command

or every 15 minutes

*/15 * * * * /path/to/command

Note that the day-of-week goes from 0-6 where 0 is sunday.

You can read more here.

share|improve this answer
These are system-wide and run with high privileges. I wouldn't put anything there unless there is a pressing need for access or permission. As a rule of thumb, try to do stuff without capabilities. Therefore, I like this answer better:… – Marcelo Morales Aug 16 '10 at 21:29
@Marcelo Morales, Which also will run the given commands as root! if you on the other hand doesn't use sudo then you will create a user crontab and this will be run as the user who created it! – LassePoulsen Aug 16 '10 at 21:44
*/15 * * * * /path/to/command was very handy for me! thanks! – ao789 Feb 21 '13 at 11:18
It's worth noting these changes are applied automatically, you don't need to restart/reload anything. – Molomby Dec 12 '13 at 1:26
Do I need to restart the Cron service after making modifications using crontab? – W.M. May 23 at 21:12

If the job you want to run can be run with the same privileges as your user I recommend using a user crontab which you can edit by running EDITOR="gedit" crontab -e(which will used gedit to edit the crontab file) or simply crontab -e(which will use the default editor) in a terminal.

If you want to run something every 10 minutes, for example, you add a line like this

*/10 * * * * /usr/bin/somedirectory/somecommand

and save the file.

You can see the contents of the user crontab with crontab -l.

The most flexible way is to use the system crontab which you can edit by running sudo crontab -e in a terminal. This will allow you to run your commands as root (in case you need that level of privilege) or any other user on the system.

Then if you want to run something every 10 minutes as root, for example, you add a line like this

*/10 * * * * root /usr/bin/somedirectory/somecommand

and save the file.(notice the addition of the user to the line)

You can see the contents of the system crontab file with sudo crontab -l.

More details at:

share|improve this answer

If you prefer to do it using a GUI, you can go to the Software Center and install Scheduled tasks (or run sudo apt-get install gnome-schedule). It will provide a powerful GUI to add cron tasks.

Note that if you use this method, tasks by default will be executed as your own user, not as root. This is usually a good thing.

share|improve this answer
+1 for GUI option! – Marco Ceppi Aug 16 '10 at 15:18

I recommend KDE's Task Scheduler (kde-config-cron) Install kde-config-cron. Access it from the System Settings in the Task Scheduler module there.

It manages both personal and system Crontabs, and the ease of creating the time boundaries greatly surprised me (see the screenshot below). I think this part is really underrated.

enter image description here

share|improve this answer

KDE Task Scheduler will not work in regular Ubuntu. It works only in KDE Systems like KUbuntu. For non KDE system you will prefer to use gnome-schedule

$ sudo apt-get install gnome-schedule

The app is Scheduled tasks in the Dash.

share|improve this answer

protected by heemayl Apr 25 at 7:30

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.