DEV Community

Cover image for How to Schedule Tasks with cron in Linux
Dishang Soni for ServerAvatar

Posted on • Originally published at serveravatar.com

How to Schedule Tasks with cron in Linux

Schedule Tasks with cron in Linux to automate routine jobs like sending reminders, cleaning files, or running backups without lifting a finger. Cron acts like your personal assistant, working 24/7 to silently schedule and execute tasks at the exact time you want.

Managing tasks efficiently on Linux system often means automating repetitive jobs. Instead of manually running scripts or commands, you can use cron, one of the most powerful task schedulers built into Linux. Whether you want to automate system maintenance, schedule backups, run scripts at specific times, cron makes the process seamless.

In this guide, we’ll walk through everything you need to know about scheduling tasks with cron in Linux, from the basics of cron syntax to advanced scheduling tips.

What is cron in Linux?

cron is time-based job scheduler. It allows users to schedule commands or scripts to run automatically at specific times, dates, intervals. The name comes from the Greek word chronos, that means "time".

Cron jobs are incredibly useful for automating routine tasks such as:

  • Running backups
  • Clearing cache
  • Sending automated reports
  • Monitoring server health
  • Updating system packages
  • and many more

Understanding How cron Works

At its core, cron relies on background process (cron daemon) that checks the crontab (cron table) for scheduled tasks. When system clock matches schedule defined in crontab, the corresponding command is executed.

Key components include:

  • cron daemon (crond): Runs continuously in background.
  • crontab file: Stores list of cron jobs for each user.
  • cron syntax: Defines time and frequency of tasks.

Cron Job Syntax Explained

The syntax of cron job may seem intimidating at first, but once you break it down, it’s straightforward:

`* * * * * command-to-execute


| | | | |
| | | | +----- Day of the week (0-6, Sunday=0)
| | | +------- Month (1-12)
| | +--------- Day of month (1-31)
| +----------- Hour (0-23)
+------------- Minute (0-59)`

How to Schedule Tasks with cron in Linux-ServerAvatar

Example:

30 2 * * * /home/user/backup.sh

Each * represents a field:

  • Minute (0–59)
  • Hour (0–23)
  • Day of the month (1–31)
  • Month (1–12)
  • Day of the week (0–6, where 0 = Sunday)

Special Strings in cron

Instead of using numbers, cron also supports special strings for common schedules:

  • @ reboot → Run once at system startup.
  • @ yearly or @ annually → Run once a year.
  • @ monthly → Run once a month.
  • @ weekly → Run once a week.
  • @ daily or @ midnight → Run once a day.
  • @ hourly → Run once an hour.

Example:

@daily /usr/bin/updatedb

This updates the file index once a day.

Read Full Article: https://serveravatar.com/schedule-tasks-cron-linux/

Top comments (0)