cron Command in Linux

Last Updated : 7 Mar, 2026

Cron is a time-based job scheduling utility available in Linux and Unix-like operating systems. It runs as a background daemon process and automatically executes scheduled tasks at predefined times without user intervention. System administrators commonly use cron to automate repetitive tasks such as backups, updates, and file synchronization.

  • Runs as a daemon process in the background
  • Automates repetitive and scheduled tasks
  • Executes jobs based on time-field matching
  • Supports per-user and system-wide scheduling
  • Allows controlled access using cron.allow and cron.deny

Working of Cron

Cron operates as a background service that continuously monitors scheduled jobs and executes them when their defined time matches the system time.

  • The cron daemon starts automatically when the system enters multi-user mode (traditionally via /etc/init.d or a systemd service).
  • It continuously checks scheduled job entries stored in crontab files.
  • Every minute, cron compares the current system time with the time fields defined in crontab.
  • If the time fields match, the specified command or script is executed.
  • Any output generated is emailed to the user unless redirected to a file.
  • By default, cron runs tasks silently in the background unless logging or redirection is configured.

Example 1: Start Cron in Foreground Mode

Run cron in the foreground for debugging or testing purposes.

Command:

cron -f
  • -f: Prevents cron from daemonizing and keeps it running in the foreground.
  • Useful to see errors or log messages directly in the terminal.

Output:

Cron will start and continuously monitor scheduled jobs in the terminal without exiting. Logs appear directly on the console.

Example 2: Enable LSB-Compliant Names

Ensure /etc/cron.d files follow LSB naming conventions.

Command:

cron -l

Explanation:

  • -l: Activates LSB-compliant naming for cron files.
  • Important in enterprise environments with standardized cron configurations.

Output:

Cron starts normally, enforcing LSB naming standards for cron configuration files. No direct terminal output unless logging is enabled.

Example 3: Start Cron with Logging Enabled

Log the start and end of all cron jobs for monitoring.

Commnad:

cron -L 3

Explanation:

  • -L 3: Logs both job start (1) and job end (2) because 1+2=3.
  • Helps system administrators track execution of scheduled tasks.

Output:

Cron runs as a daemon, and logs for job start and job completion are written to the system log (e.g., /var/log/syslog or /var/log/cron.log depending on configuration).

Cron Daemon Syntax

The cron daemon can be started manually using the following syntax:

cron [-f] [-l] [-n] [-L loglevel]
  • cron: Starts the cron daemon
  • -f: Runs cron in foreground mode
  • -l: Enables LSB-compliant names for /etc/cron.d
  • -n: Adds FQDN to mail subject
  • -L loglevel: Defines logging behavior

Note: This syntax is mainly used for debugging, testing, or container-based environments.

Cron Daemon Options

1. -f (Foreground Mode)

Runs cron in the foreground instead of as a background service. Useful for debugging or testing cron behavior.

Syntax:

cron -f

Example: Check Cron Jobs in Real Time

Runs cron in the terminal, so you can see when jobs start or fail immediately.

Command:

cron -f

Output:

Cron starts and continuously monitors scheduled jobs directly in the terminal. Log messages and errors appear on the console.

2. -l (Enable LSB-Compliant Names)

Enables Linux Standard Base (LSB) compliant naming for /etc/cron.d files. Ensures cron configuration files in /etc/cron.d follow standard Linux naming rules. Helps maintain standardized cron configurations.

Syntax:

cron -l

Example: Standardize Cron File Names

Useful in servers that follow Linux Standard Base (LSB) rules for configuration files.

Command:

cron -l

Output:

Cron runs normally. It will enforce correct file naming for /etc/cron.d, but no terminal output is seen unless logging is enabled.

3. -n (Include FQDN in Mail Subject)

Adds the Fully Qualified Domain Name (FQDN) to email notifications sent by cron jobs. Useful in multi-server setups.

Syntax:

cron -n

Example: Identify Server in Cron Emails

If a job runs on multiple servers, this helps you know which server sent the email.

Command:

cron -n

Output:

Cron runs as a daemon. Any email sent for cron job output includes the host FQDN in the subject.

4. -L loglevel (Control Logging)

Specifies what cron should log about the jobs. You can log job start, end, failures, or process IDs.

Syntax:

cron -L <loglevel>

Loglevel Values:

1: Log start of jobs

2: Log end of jobs

4: Log failed jobs (exit status ≠ 0)

8: Log process IDs of cron jobs

Example: Log Job Start and Completion

Command:

cron -L 3

Output:

Cron runs as a daemon. Job start and job completion events are logged in the system log (/var/log/syslog or /var/log/cron.log).

Crontab Overview

Crontab (cron table) is a configuration file that stores scheduled tasks. Each entry in crontab defines a command or script that should run automatically at a specific time or interval. Crontab allows users to add, modify, or remove scheduled tasks, automate repetitive operations like backups, updates, or log cleaning, run tasks in the background without manual intervention

  • Users must have permission to use cron (cron.allow and cron.deny)
  • Jobs are executed silently in the background unless output is redirected
  • Crontab entries follow a strict time-field structure for scheduling

Note: Each user can have their own crontab file, and the system also maintains a global crontab for system-wide jobs.

Crontab Time Field Structure

Each crontab entry has six fields separated by spaces. The first five fields define when the task will run, and the last field specifies what command or script to execute.

 * * * * * command_to_run
| | | | |
| | | | └── Day of Week (0–6 or Sun–Sat)
| | | └──── Month (1–12 or Jan–Dec)
| | └────── Day of Month (1–31)
| └──────── Hour (0–23)
└────────── Minute (0–59)
  • Minute: 0–59: The minute of the hour to run the job
  • Hour: 0–23: The hour of the day to run the job
  • Day of Month: 1–31: The day of the month
  • Month: 1–12 or Jan–Dec: The month of the year
  • Day of Week: 0–6 or Sun–Sat: Day of the week (0 = Sunday)
  • Command: The script or command that should be executed
Comment
Article Tags:

Explore