Mastering Cron: Create, Schedule, and Manage Linux Cron Jobs
This guide explains what cron timers are, how to create cronjobs using the crontab command, the syntax of cron expressions—including fields for minute, hour, day, month, and weekday—as well as shortcut macros, and how to edit or stop scheduled jobs on Linux.
What Is a Cron Timer?
Cron is a scheduling utility that automatically runs commands at specified times. Each scheduled task is called a cronjob and is defined in a crontab file.
Creating a Cronjob
To create a new cronjob, invoke the crontab command with the -e option, which opens the default editor for the crontab file: $ crontab -e If you want to specify a different editor, set the EDITOR environment variable before running the command, for example:
EDITOR=nano crontab -eCron Syntax
A cron expression consists of five space‑separated fields that define when the command runs:
Minute (0‑59)
Hour (0‑23, where 0 is midnight)
Day of month (1‑31)
Month (1‑12)
Day of week (0‑6, where 0 is Sunday)
The asterisk ( *) means “every”. For example, the following expression runs a backup script at minute 0 of every hour, every day: /opt/backup.sh 0 * * * Another example runs the script at 03:30 every Sunday:
/opt/backup.sh 30 3 * * 0Shortcut Macros
Modern cron implementations support shortcut macros that replace full expressions: @hourly – at minute 0 of every hour @daily – at 00:00 each day @weekly – at 00:00 on Sunday @monthly – at 00:00 on the first day of each month
Using a macro, the same daily backup can be scheduled as:
/opt/backup.sh @dailyStopping or Removing a Cronjob
To stop a cronjob, edit the crontab file again, delete the line containing the unwanted command, and save the file: EDITOR=nano crontab -e Alternatively, you can terminate a running process with standard Linux process‑management commands.
Automation Note
Once the crontab file is saved and the editor exits, the cron daemon automatically schedules the jobs, handling execution without further user intervention.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
