đź•’ Cron Jobs for Beginners: Automating Tasks Made Easy


Have you ever wished your computer could take care of routine tasks while you sleep? Maybe you want to back up files every day, send a report email every Monday, or clean up some logs at midnight. Sounds like a dream?
Well, welccome to the world of Cron Jobs — the secret too, that helps you automate tasks on Linux systems, and saves you from the “Did I forget do that again?” moments.
In this guide, we’ll walk through everything you need to know as a complete beginner — what cron is, why it’s used, how to write cron jobs, the syntax (don’t worry, we’ll break down), and common examples you can use right away.
What Exactly is a Cron Job?
Let’s start simple.
A Cron Job is a scheduled task in Unix-based systems (like Linux or macOS) that runs automatically at specific intervals — such as every minute, hour, day and week, or even just once at reboot.
Imagine it like setting alarms or reminders on your phone, but for your computer to run scripts or commands on your behalf.
The word “cron” comes from the Greek word “chronos” which means time. So yes, it’s your time-keeping assistant.
Why Use Cron Jobs?
Here’s what cron jobs are perfect for:
Automating repetitive tasks (like backups or cleanups)
Scheduling system maintainance scripts
Syncing files or uploading data to servers
Sending automated emails or notifications
Generating reports on a regular basis
Cleaning up logs or temp files to save disk space
Instead of manually doing these things every day or week, cron handles it for you. Set it and forget it.
How Do Cron Jobs Work?
Cron jobs are written in a file called the crontab (short for “cron table”).
Each user on the system can have thier own crontab. You edit it to define what task you want to run, and when to run it.
To open the crontab, run this command:
crontab -e
This will open your personal cron table in the default text editor (usually nano
or vim
).
To view the list of you current cron jobs:
crontab -l
To delete all you cron jobs:
crontab -r
(Be careful with -r
— it removes all your scheduled tasks!)
Understanding the Cron Syntax
Here’s what a typical cron job looks like:
* * * * * /path/to/your/script.sh
| | | | |
| | | | └── Day of the week (0 - 7) (Sunday is 0 or 7)
| | | └──── Month (1 - 12)
| | └────── Day of the month (1 - 31)
| └──────── Hour (0 - 23)
└────────── Minute (0 - 59)
Let’s break it down:
*
is a wildcard — it means “every“.Each field represents a time unit (minute, hour, day, etc.)
The final part is the command or script you want to run.
Example
0 5 * * * /home/anand/backup.sh
This runs the backup.sh
script every day at 5:00 AM. Simple, right?
Common Cron Job Schedules
Here are a few examples you might actually use:
Task | Cron Expression | Description |
Every minute | * * * * * | Runs every minute |
Every 5 minutes | */5 * * * * | Runs every 5 minutes |
Every hour | 0 * * * * | At the start of every hour |
Every day at midnight | 0 0 * * * | At 12:00 AM daily |
Every Monday at 9 AM | 0 9 * * 1 | Every Monday morning |
On the 1st of every month at 1 AM | 0 1 1 * * | Great for monthly reports |
Every Sunday | 0 0 * * 0 | Weekly task on Sunday |
Need help generating these? Use crontab.guru — a fantastic online tool to visualize cron expressions.
Setting Up a Cron Job (Step-by-Step)
Let’s say you have a script cleanup.sh
that deletes temporary files in a folder.
Make your script executable:
chmod +x /home/anand/scripts/cleanup.sh
Test your script manually to make sure it works:
/home/anand/scripts/cleanup.sh
Open crontab:
crontab -e
Add your job to run daily at 3 AM:
0 3 * * * /home/anand/scripts/cleanup.sh >> /home/anand/logs/cleanup.log 2>&1
This not only runs your script but also saves its output to a log file (which is super helpful for debugging).
Bonus: Special Keywords for Simplicity
Instead of writing the full syntax, cron also supports shortcuts:
Keyword | Equivalent To |
@reboot | Run once at system boot |
@hourly | 0 * * * * |
@daily | 0 0 * * * |
@weekly | 0 0 * * 0 |
@monthly | 0 0 1 * * |
@yearly | 0 0 1 1 * |
Example:
@reboot /home/anand/scripts/start-server.sh
This command runs once when your system boots up. Super useful for starting services automatically.
Best Practices and Gotchas
Use full paths in scripts and cron jobs. Environment variables like $PATH are limited in cron.
Always test your script manually before adding it to cron.
Log everything! Redirect output and errors to a log file:
* * * * * /path/to/script.sh >> /path/to/log.log 2>&1
Keep it simple: start with a small task and build confidence.
Don’t forget permissions: your script must be executable!
Wrapping up!
If you’ve made it this far — congratulations! 🎉 You now know more about cron jobs than most beginners. Cron is like a behind-the=scenes superhero that quietly takes care of things for you — saving time, effort, and sometimes… your job!
Start small. Maybe automate a backup today. Slowly, you’ll get the hang of it and realize how much more productive your system (and you) can become.
Subscribe to my newsletter
Read articles from Anand Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Anand Kumar
Anand Kumar
"Passionate about the art of storytelling and the logic of coding, I find joy in exploring new worlds through books and building innovative solutions through programming. Always eager to learn and grow, I blend creativity and technology to craft a unique narrative in everything I do. When I'm not lost in a novel, you'll find me debugging code or exploring the latest in tech."