Linux includes a built-in tool designed to automate routine tasks. Instead of remembering to run commands manually, you can tell the system to run them automatically at a specific time.
This tool is called cron.
Cron is commonly used by system administrators and IT professionals to automate maintenance work such as backups, log cleanup, and service checks. Once configured, these tasks run in the background without requiring manual intervention.
This guide walks through the simplest way to begin using cron. By the end, you will know how to create a scheduled task, verify that it works, and avoid common beginner mistakes.
What Cron Does
Cron is a task scheduler.
That means you can tell Linux:
Run this command
At this time
Automatically
Once configured, the system runs the task according to the schedule you define.
Some common examples include:
• running a backup every night
• cleaning logs once a week
• restarting a service each morning
Before creating a scheduled job, it helps to see where these tasks are stored.
Viewing Your Current Cron Jobs
Scheduled cron tasks are stored in something called a crontab.
The word crontab simply means cron table. It is a list of commands that Linux will run automatically.
To see your current scheduled tasks, run:
crontab -l
Example output:
no crontab for user
This message means no scheduled jobs exist yet. That is normal on a new system.
Next, we will create one.
Opening the Cron Editor
To create or edit scheduled tasks, use:
crontab -e
Press Enter.
Linux will open a text editor. On many systems this editor is nano, which is beginner friendly.
You may see something similar to this:
# Edit this file to introduce tasks to be run by cron.## Each task to run has to be defined through a single line
Lines beginning with # are comments. They provide instructions but are not executed.
Your scheduled jobs will be written on new lines below these comments.
Understanding the Cron Schedule Format
Every cron job has two parts.
-
The schedule
-
The command
The schedule contains five time fields:
minute hour day-of-month month day-of-week
Example format:
* * * * * command
The asterisk * means every possible value.
So:
* * * * *
Means:
Every minute
Of every hour
Of every day
Of every month
On every day of the week
This schedule would run the command once every minute.
Creating Your First Cron Job
Let’s create a safe example.
We will schedule Linux to write the current time to a file once every minute.
Add this line to the crontab:
* * * * * date >> ~/cron-test.txt
Now break down what this means.
The Schedule
* * * * *
Run every minute.
The Command
date
The date command prints the current system time.
Output Redirection
>>
This tells Linux to append the output to a file instead of printing it to the terminal.
The File
~/cron-test.txt
Each time cron runs, a new timestamp will be added to this file.
Saving the Cron Job
If your editor is nano:
Save with:
CTRL + O
Press Enter.
Then exit with:
CTRL + X
You should see a message similar to:
crontab: installing new crontab
This confirms the scheduled task has been installed.
Cron is now running your job automatically.
Verifying the Job Worked
Cron checks tasks every minute.
After about one minute, check the output file:
cat ~/cron-test.txt
Example output:
Tue Mar 14 12:01:00 UTC 2026Tue Mar 14 12:02:00 UTC 2026
Each time cron runs the command, another line is added.
This confirms your cron job is working correctly.
Understanding Cron Schedule Examples
Now that you have a working example, let’s look at a few common schedules.
Example:
0 2 * * * command
Meaning:
Minute: 0
Hour: 2
This runs the command every day at 2:00 AM.
Another example:
0 3 * * 0
Meaning:
3:00 AM
Every Sunday
Day of week values:
0 = Sunday1 = Monday2 = Tuesday
Using these fields, you can schedule tasks at very specific times.
Editing Existing Cron Jobs
To modify scheduled tasks later, simply run:
crontab -e
Your current cron jobs will open in the editor.
You can change the schedule or command, then save the file.
Cron automatically updates the schedule after saving. No service restart is required.
Removing a Cron Job
To remove a job, delete its line from the crontab and save the file.
If you want to remove all cron jobs, you can run:
crontab -r
Use this command carefully. It deletes the entire crontab immediately.
Common Beginner Mistakes
Using Relative Paths
Cron runs in a limited environment.
Commands like this may fail:
backup.sh
Instead, use the full path:
/home/user/backup.sh
To locate the full path of a command:
which command-name
File Permissions
If a script is not executable, cron cannot run it.
Fix this with:
chmod +x script.sh
Expecting Instant Results
Cron checks jobs once per minute.
If you schedule a job every minute, it may take up to 60 seconds before the first execution occurs. This delay is normal.
A Real IT Example
Temporary files and logs can accumulate over time.
A common maintenance task is clearing temporary directories once per week.
Example cron job:
0 2 * * 0 rm -rf /tmp/*
This means:
Minute: 0
Hour: 2
Day of week: Sunday
So the cleanup runs every Sunday at 2:00 AM.
Tasks like this allow servers to maintain themselves automatically without manual oversight.
A Useful Next Step
Once you are comfortable with cron, you can schedule scripts.
For example, create a backup script called:
backup.sh
Then schedule it with cron:
0 1 * * * /home/user/backup.sh
This would run your backup every night at 1:00 AM.
Automating backup scripts is one of the most common real-world uses of cron on production systems.
Conclusion
Cron is one of the most practical tools available in Linux.
Once you understand the basic schedule format, you can automate many routine tasks. Backups, log cleanup, monitoring checks, and maintenance scripts can all run automatically.
The best way to become comfortable with cron is simple practice. Create a few test jobs, watch them run, and adjust the schedules.
With a little repetition, scheduling tasks with cron becomes second nature.