Privacy Policy
© 2026 linux101.dev

CRON Command Cheatsheet

CRON is a time-based job scheduler in Unix-like operating systems. It allows you to automate tasks by running commands or scripts at specific intervals - such as horly, daily, weekly, or even at custom times.

Key Concepts

Cron Daemon (crond)

The background service that executes scheduled tasks. Runs continuously and checks for tasks to run at their specified times.

Crontab (Cron Table)

A configuration file that defines the schedule and commands for cron jobs. Each user can have their own crontab file.

Cron Syntax

A cron job in system-wide crontab (/etc/crontab) and files in /etc/cron.d/* is defined in the following format:

* * * * * user command_to_execute

here the 'user' is required; cron runs command as that user.

The five asterisks represent time and date fields:
  1. Minute (0–59)
  2. Hour (0–23)
  3. Day of the month (1–31)
  4. Month (1–12)
  5. Day of the week (0–7, where both 0 and 7 represent Sunday)

For per-user crontab (from crontab -e) format is:

* * * * * command_to_execute

Examples of Cron Jobs

Every minute:

* * * * * command

Every 5 minutes:

*/5 * * * * command

Daily at 3 AM (explicit):

0 3 * * * command

Every Monday at 5 PM

0 17 * * 1 command

First day of the month

0 0 1 * * command

Common macros (alternative shorthand):

@hourly command
@daily command
@weekly command
@monthly command
@yearly command

Runs the 'command' once when the machine (or cron service) starts:

@reboot command

Crontab

Cron jobs are defined in user's contab file. They can be listed with

crontab -l

Opening the crontab file for edit (add lines in the format above to add new jobs, then save and exit):

crontab -e

Worth to redirect output to a log file for debugging (otherwise email is attempted if mail subsystem is set up):

 * * * * * /path/to/script.sh >> /path/to/logfile.log 2>&1 

Remove all Cron Jobs:

crontab -r

Setting up environment variables for Cron jobs

Variables set at the top of the crontab apply globally to every entry in that file. In user crontab (crontab -e) this means all jobs inherit them; in /etc/crontab or /etc/cron.d/*, they apply the same way for that file.

 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/bash
MAILTO=""

To override for a single job, include the env assignment on that line before the command or use a wrapper script with its own environment setup.

 0 4 * * * /usr/bin/env VAR=value /usr/local/bin/mytask.sh >> /var/log/mytask.log 2>&1