Skip to content

cron

Learn how to schedule and automate tasks in Linux using cron jobs.

Task Scheduling & Management

Common commands for checking, editing, and managing crontab jobs.

Check Service Status

Ensure that the cron daemon service is installed and running.

Terminal window
systemctl status <service_name>
Example
systemctl status cron

Edit User Crontab

Open the crontab editor for the current user.

Terminal window
crontab -e

List Scheduled Jobs

View existing cron jobs for the current user.

Terminal window
crontab -l

Remove All Jobs

Clear the current user’s entire crontab.

Terminal window
crontab -r

Edit System Crontab

Open the system-wide crontab configuration file.

Terminal window
sudo nano /etc/crontab

Syntax Blueprint

Cron jobs use a five-field time format followed by the command to execute.

Terminal window
# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of week (0–6, Sun=0)
# │ │ │ │ │
# * * * * * command_to_execute

Scheduling Examples

Common practical examples of scheduling tasks with cron.

Run Daily at Midnight

Executes a shell script every day at 12:00 AM.

Terminal window
0 0 * * * <script_path>
Example
0 0 * * * /home/user/backup.sh

Run Every 15 Minutes

Executes a python script at a frequent interval.

Terminal window
*/15 * * * * <interpreter> <script_path>
Example
*/15 * * * * /usr/bin/python3 /home/user/task.py

Run Weekly Cleanup

Executes a system maintenance command every Sunday at 3:00 AM.

Terminal window
0 3 * * 0 <command>
Example
0 3 * * 0 root /usr/bin/apt autoremove -y