Creating a cron job in Linux keeps routine commands running on schedule without leaving a terminal open. That is useful for recurring backups, cleanup tasks, report generation, and other maintenance that should happen at a predictable time.
The standard Linux workflow stores one account's recurring jobs in a personal crontab managed with crontab. Each active line contains five time fields followed by the command, and the daemon that provides cron service, commonly cron or crond, checks those schedules every minute.
Cron jobs run with a smaller shell environment than an interactive terminal, so absolute paths, deliberate output redirection, and explicit environment lines can prevent silent failures. These steps assume a working cron daemon is already installed and started, the schedule follows the daemon's local timezone unless CRON_TZ is set, and any unescaped % inside the command becomes a line break passed to the shell.
Related: How to list cron jobs in Linux
Related: How to automate Linux backups
Steps to create a cron job in Linux:
- Decide on the schedule and the exact command before opening the crontab.
# m h dom mon dow command */15 * * * * /usr/local/bin/report-health.sh 0 2 * * * /usr/local/bin/backup-home.sh @daily /usr/local/bin/cleanup-temp.sh
The five fields are minute, hour, day of month, month, and day of week. Shorthand forms such as @hourly, @daily, and @reboot are widely supported on Linux.
If both the day-of-month field and the day-of-week field are restricted, cron runs the command when either field matches.
- Open the current user's crontab in the editor chosen by $VISUAL or $EDITOR.
$ crontab -e
The first run may ask which editor to use. Use sudo crontab -e only when the scheduled command truly needs to run as root.
- Add the cron environment lines and job entry in the editor so a UTC timestamp is appended to /tmp/cron-proof.log every minute.
SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin MAILTO="" * * * * * /bin/date -u +\%Y-\%m-\%dT\%H:\%M:\%SZ >> /tmp/cron-proof.log 2>&1
Use absolute paths for commands, scripts, and log files because cron usually runs with a minimal PATH.
Escape each % inside the command as \% when the command contains date format strings or similar placeholders.
- Save the file and exit the editor so crontab installs the updated schedule automatically.
Do not edit files under /var/spool/cron or /var/spool/cron/crontabs directly. The crontab command installs the entry in the correct format for the current account.
- List the current user's crontab and confirm that the new job is present exactly as intended.
$ crontab -l SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin MAILTO="" * * * * * /bin/date -u +\%Y-\%m-\%dT\%H:\%M:\%SZ >> /tmp/cron-proof.log 2>&1
Saving the file is normally enough. Linux cron daemons load the updated crontab automatically, so a service restart is not usually required.
Use How to list cron jobs in Linux when the job might belong to another account or a system-wide cron file such as /etc/crontab or /etc/cron.d/.
- Wait for the scheduled time to pass, then inspect the output from the proof job.
$ cat /tmp/cron-proof.log 2026-04-14T11:30:01Z
A new timestamp confirms that cron matched the schedule and ran the command successfully.
- Replace the test command with the real workload after the schedule is confirmed.
$ crontab -e
Keep the same schedule and swap only the command, or change the schedule to the real interval after the proof entry has been validated.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
