How to Run Cron Jobs Every Minute, Hour, Day on Ubuntu Linux
Cron jobs run automated tasks on a schedule in Ubuntu Linux so you do not have to trigger backups, clear temporary files, or handle routine system maintenance by hand. A crontab file holds these scheduled commands using a line of five special time-code symbols, such as setting */1 * * * * to run a script every minute.
This built-in tool saves you from repeating manual commands in the terminal. You manage the schedule directly through text commands to keep your system running on time every day.
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
Setting up cron jobs Ubuntu tasks involves editing your system crontab file, which acts as a master schedule for automated background commands. You can open this file using terminal commands to define exactly when scripts, backups, and system updates run automatically without manual input.
Here is how to use cron jobs to perform tasks at specific intervals.
Crontab (cron table) is a text file holding scheduled tasks. Each line in a user crontab file contains six parts, starting with the time schedule and ending with the command to run.
An example cron file appears similar to the block 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, writing 1-5 in the Day of Week field targets Monday through Friday.
Commas separate individual times within a schedule. Writing 1,2,3 in the Hour field triggers execution at 1 AM, 2 AM, and 3 AM. If no specific day gets set, execution happens daily at those specified hours. You can also combine operators. For example, 1,2,5-8 runs tasks at 1 AM, 2 AM, and every hour from 5 AM through 8 AM.
This field tells cron which user should run the job.
Cron scheduling jobs offer robust control over system tasks. Understanding how cron schedules jobs provides a solid foundation for automating routine operations on an Ubuntu Linux system.
How to schedule a cron job to run every 5 minutes
To make the cron job run every 5 minutes, enter the line below in the crontab file.
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:
*/10 * * * * ~/scripts.sh
How to run a cron job every 10 minutes
Running a cron job every 10 minutes on Ubuntu requires adding a specific time schedule string using the forward slash syntax inside your crontab file. This tells the system to run your script automatically six times every hour so you do not have to trigger updates manually.
*/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.
* * * * * ~/script.sh
# 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 completes the setup process.
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.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.
[…] How to run cron jobs on Ubuntu […]