How to create a cron job on Linux
On this page
To create a cron job, run crontab -e, add one line made of five schedule fields and a command, then save the file. Cron installs the change by itself and starts running the line at the next matching minute. The steps are the same on Ubuntu, Debian, Fedora and most other Linux systems.
How do you create a cron job step by step?
- Run the command by hand first. Use the full path of every program and file, such as
/usr/local/bin/backup.sh. If it fails in your terminal it will fail in cron. - Make a script executable.
chmod +x /usr/local/bin/backup.sh, and start the file with a line such as#!/bin/bash. - Open your crontab.
crontab -eopens the file in the editor named by VISUAL or EDITOR. The first time, Debian and Ubuntu ask you to pick an editor. - Add one line. Five schedule fields, then the command.
- Save and quit. Cron reads the new file on its own. There is nothing to restart.
- Read it back.
crontab -lprints the file as installed.
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1That line runs backup.sh at 02:30 every day and appends its output to a log file. Cron needs each line to end in a newline, so keep an empty line after the last entry. The five fields are explained in the cron syntax cheat sheet, and the cron expression translator reads any line back in plain English.
How do you test a new cron job?
Do not wait for 02:30 to find a typo. Set the schedule to every minute for the first test, wait for the next minute, then check that the command ran:
* * * * * /bin/date >> /tmp/cron-test.logWhen /tmp/cron-test.log gains a line a minute, cron is working and the schedule is read. Swap in the real command and the real schedule, and delete the test line. If nothing appears, go through cron job not running, and see how to check whether a cron job ran.
How do you create a cron job as root or for another user?
| Goal | Command | Runs as |
|---|---|---|
| Your own jobs | crontab -e | You |
| Jobs that need root | sudo crontab -e | root |
| Another user's jobs | sudo crontab -u appuser -e | appuser |
| A system job with a user column | A file in /etc/cron.d, or /etc/crontab | The user named in the line |
Lines in /etc/crontab and in /etc/cron.d have an extra field between the schedule and the command: the name of the user that runs it. Lines in a personal crontab have no such field. Putting a username in a personal crontab line makes cron try to run it as a command. Where cron jobs are stored lists every place a job can live.
How do you edit, disable and remove a cron job?
- Edit:
crontab -eand change the line. - Switch one off: put a
#in front of the line. It stays in the file for later. - Remove one: delete its line in
crontab -e. - Remove all of them:
crontab -rdeletes your whole crontab at once, with no confirmation.crontab -i -rasks first, andcrontab -l > backup.txtsaves a copy before you start.
What do you add so that a failure does not go unnoticed?
A new cron job gives no sign when it stops. Add a request to a monitoring URL after the command, joined with && so that it is sent only after a successful run, and give it a timeout:
30 2 * * * /usr/local/bin/backup.sh && curl -fsS --max-time 10 --retry 5 -o /dev/null https://ping.cronmissed.com/5f0c1b2e-7a3d-4c8e-9b61-2d4f8a7e3c10Create a check with the same schedule and CronMissed alerts you when the request is late. The crontab guide shows the setup, and what is cron job monitoring? explains why a silent job needs one.
Sources
- crontab(5) manual page , read 26 November 2026
- crontab(1) manual page , read 26 November 2026
Questions and answers
- Run crontab -e, choose an editor if asked, add a line such as 30 2 * * * /usr/local/bin/backup.sh, and save. Ubuntu starts the cron service at boot, so nothing else needs enabling.
- No. crontab -e installs the file when you quit the editor, and cron picks up the change by itself. Editing a file in /etc/cron.d is also read without a restart.
- Cron runs with a short PATH and none of your shell profile. Use full paths and set variables in the crontab; cron environment and PATH goes through the causes.
- Use */5 * * * * as the schedule. Make sure a run can finish within 5 minutes, or two runs will overlap; see overlapping cron runs.
How do I create a cron job in Ubuntu?
Do I need to restart cron after editing the crontab?
Why does my cron job work in the terminal but not from cron?
How do I create a cron job that runs every 5 minutes?
Create a check, add one curl to the job, and CronMissed alerts you when a ping is late or reports a failure.
Start monitoring