cron
Schedule commands to run automatically
TLDR
View documentation for managing cron entries
SYNOPSIS
cron [-f] [-l <loglevel>] [-n] [-x [<debugflags>]]
PARAMETERS
-f
Do not daemonize; run in foreground
-l <loglevel>
Set log verbosity (0=emergency to 8=debug)
-n
Run once without daemonizing (for testing)
-x [<debugflags>]
Enable debug flags (e.g., a=audit, d=db debug; ? for help)
DESCRIPTION
The cron command runs as a background daemon (crond) that executes scheduled jobs defined in crontab files. It periodically checks for tasks due to run, based on time specifications like minute, hour, day, month, and weekday. Jobs are typically user-specific (/var/spool/cron/crontabs/<username>) or system-wide (/etc/crontab, /etc/cron.d/*).
Cron wakes every minute to scan crontabs, matching entries against the current time. Matched jobs run via /bin/sh with the user's environment (HOME, LOGNAME, PATH, SHELL set; others from /etc/environment). Output is mailed to the user or discarded if MAILTO is unset.
Key features include flexible scheduling (e.g., * * * * * for every minute), ranges (@hourly, @daily aliases), and environment variables in crontabs. It's ideal for backups, logs rotation, and periodic maintenance. Access requires editing via crontab -e; direct file edits are insecure as files are mode 600, owned by root.
Modern systems may use systemd timers as alternatives, but cron remains ubiquitous for its simplicity and POSIX compliance. Logs go to syslog (/var/log/cron or /var/log/syslog).
CAVEATS
Requires root to start daemon; per-user crons need crontab command. Jobs run with limited env; absolute paths advised. No built-in locking; race conditions possible. IPv6 support varies by implementation.
CRONTAB FORMAT
Fields: minute hour day month weekday command
*=any; ranges/steps (1-5/2); lists (1,3,5); @aliases (@reboot, @yearly).
DEFAULT PATHS
User: /var/spool/cron/crontabs/<user>
System: /etc/crontab, /etc/cron.d/*, /etc/cron.{hourly,daily,weekly,monthly}.
HISTORY
Originally written by Brian Fenton in 1975 for Unix V7. Rewritten by Paul Vixie in 1987 (Vixie Cron), becoming the standard. FCron/DCron variants exist for features like locking/portability. Integrated into most distros; systemd integration in newer systems.


