Skip to content
Follow
Ubuntu Linux

How to Run Cron Jobs every Minute, Hour, Day on Ubuntu Linux

Richard
Written by
Richard
Jul 30, 2022 Updated Jul 14, 2026 4 min read
Enable Automatic Suspension in Ubuntu Linux Easily
Enable Automatic Suspension in Ubuntu Linux Easily

Cron jobs let you schedule tasks to run automatically on Ubuntu Linux.

A cron job is like setting an alarm on your computer. It tells your system to perform a specific action at a set time or interval, such as clearing temporary files every day or running a backup script every hour.

You edit a special file called a crontab to set these schedules. The crontab uses a simple code to tell cron exactly when to run your task. For example, typing `*/5 * * * *` means the job runs every 5 minutes.

This system is powerful for automating repetitive jobs on your Ubuntu machine, ensuring they happen exactly when you want them to.

⚡ Quick Answer

Edit your crontab file by running `crontab -e`. Use asterisks for minute, hour, or day intervals, like `* * * * *` for every minute.

How to schedule cron tasks in Ubuntu Linux

Scheduling cron tasks in Ubuntu Linux is done using a special file called a crontab. This crontab file works like a to-do list for your computer, storing commands you want to run automatically and telling the system exactly when to run them, which helps automate jobs like updates or backups.

Here’s how to use cron jobs to perform tasks at intervals.

Crontab (cron table) is a text file holding your scheduled tasks. Each line in your user crontab file has six parts: the time schedule followed by the command to run.

An example of a cron file will look similar to the one below:

The asterisk (*) acts as a wildcard in cron. It tells cron to run a task during every available time slot it represents, like every minute if used in the Minute field. This wildcard behavior applies to the hour, day, and month fields too.

The hyphen (-) lets you set a range. For instance, if you’re setting the ‘Day of Week’ field, ‘1-5’ means Monday through Friday.

Cron job schedules use a comma (,) to separate individual times. For example, '1,2,3' in the 'Hour' field means a cron job runs at 1 AM, 2 AM, and 3 AM. If no specific day is set, the cron job runs daily at the times specified within the hour field. You can combine specific times and ranges, such as '1, 2, 5-8', which means the cron job runs at 1 AM, 2 AM, and every hour from 5 AM to 8 AM.

📝Good to Know
The syntax for the system-wide crontab file includes an extra user field. This field tells cron which user should run the job.

Cron scheduling jobs offer robust control over your tasks. Understanding cron and how to schedule jobs provides a solid start for automating routine operations on your Ubuntu Linux system.

How to schedule a cron job to run every 5 minutes

If you want the cron job to run every 5 minutes, enter the line below in the crontab file.

💻Code
0,5,10,15,20,25,30,35,40,45,50,55  * * * * ~/script.sh

How to schedule a cron job to run every 10 minutes

To run a job every 10 minutes, enter the line below in the crontab file:

💻Code
*/10  * * * * ~/scripts.sh

How to run a cron job every 10 minutes

To run a cron job every 10 minutes on Ubuntu, add a specific line to your crontab file. This line tells the system to run a chosen command every ten minutes without needing you to do anything, perfect for tasks that require frequent checking or updating.

💻Code
*/15  * * * * ~/script.sh

How to run a cron job every minute

To run a cron job every minute, enter the line below in the crontab file.

💻Code
* * * * * ~/script.sh

An example cron entry for Let’s Encrypt certbot to renew certificates automatically looks like the one below:

🟨JavaScript
# the cronjob.timer function takes precedence over this cronjob.  For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a ! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

That should do it!

Conclusion:

  • Cron jobs in Ubuntu Linux are useful for automating operational and mundane tasks.
  • The key to scheduling tasks with cron jobs lies in understanding the syntax and utilizing the crontab file effectively.
  • By leveraging the asterisk, hyphen, and comma operators, users can create precise schedules for their cron jobs.
  • Examples of scheduling cron jobs at various intervals, along with a Let’s Encrypt certbot renewal cron entry, demonstrate the versatility of this feature.
  • With this understanding, users can efficiently manage and automate tasks using cron jobs in Ubuntu Linux.

Where are cron jobs in Ubuntu?

The crontab files are stored in /var/spool/cron/crontabs , with each file named for the user account that created it. You should not update these files directly; instead, you can view, update, and delete a user crontab file using the crontab command.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Mount Windows 11 Shares on Ubuntu Linux
Ubuntu Linux How to Mount Windows 11 Shares on Ubuntu Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04
How to Change Default Distro in Windows Subsystem for Linux
Windows How to Change Default Distro in Windows Subsystem for Linux

0 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *