Continuing My Learning Journey: Diving into Cron Jobs

Andrii RAndrii R
3 min read

Today, I explored one of the most practical Linux skills yet: automating tasks with cron jobs. This is a feature that allows you to schedule tasks so that your system automatically executes them at specific times or events. Think of it as teaching your computer to be proactive instead of reactive.

What is Cron?

Cron is a background service (a daemon) in Linux that is responsible for executing scheduled tasks, called cron jobs. These tasks are defined inside a special file known as the crontab (short for “cron table”). Each line in a crontab file represents a task, along with the schedule that determines when it runs.

The Structure of a Crontab

At first glance, the syntax looked terrifying to me - just numbers and symbols! But once I broke it down, it started to make sense. Each job in a crontab has five time-related fields followed by the command:

* * * * * command
- - - - -
| | | | |
| | | | +---- Day of the week (0-6 or SUN-SAT)
| | | +------ Month (1-12 or JAN-DEC)
| | +-------- Day of month (1-31)
| +---------- Hour (0-23)
+------------ Minute (0-59)

If you don’t care about a specific field, you use * (the wildcard). For example:

0 */12 * * * cp -R /home/user/Documents /var/backups/

This means: At minute 0, every 12th hour, every day, every month, regardless of the weekday, run the backup command.

Special Strings in Cron

While experimenting, I discovered that cron also supports “special strings” instead of raw numbers. For example:

In one of my exercises, I found the crontab line:

@reboot /var/opt/processes.sh

That means this script will run automatically every time the system reboots. No numbers were needed!

Hands-On Example: Backups

The example I practiced with was backing up a folder every 12 hours:

0 */12 * * * cp -R /home/cmnatic/Documents /var/backups/

This command copies the Documents folder into /var/backups/ twice a day. Imagine how useful this is for automation: backups, system checks, log rotations, or even sending notifications.

Reflections

This module felt like coding, but instead of writing applications, I was giving instructions directly to the operating system. It was one of those “jaw-dropping” moments - realizing that I can make my system do things automatically, at the exact time I want.

I also noticed something interesting: the learning material didn’t explain everything in full detail (like @reboot), and I had to figure it out myself. Maybe that’s intentional, to encourage self-research, just like in real sysadmin work. It was frustrating at first, but now I see it as part of the journey.

Key Takeaways

  • Cron = the daemon that runs tasks on schedule.

  • Crontab = the file where cron jobs are defined.

  • Five fields (minute, hour, day of month, month, day of week) control the timing.

  • Special strings like @reboot simplify common schedules.

  • Cron is powerful for automation: backups, monitoring, or running scripts.

Next up, I’ll be exploring how cron compares to systemd timers, which are more modern replacements. For now, I’m proud of unlocking cron - the first real taste of Linux automation. Next, I’m excited to dive into systemd timers and compare them with cron.

0
Subscribe to my newsletter

Read articles from Andrii R directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Andrii R
Andrii R