---
title: "How to create a cron job on Linux and Ubuntu"
url: "https://cronmissed.com/learn/create-a-cron-job.md"
canonical_url: "https://cronmissed.com/learn/create-a-cron-job"
last_updated: "2026-11-26"
type: "conceptual"
summary: "Create a cron job in five steps: test the command, open crontab -e, add one line, save, and check it with crontab -l. Includes the root crontab and removal."
related: ["https://cronmissed.com/learn.md", "https://cronmissed.com/learn/cron-syntax-cheat-sheet.md", "https://cronmissed.com/learn/list-all-cron-jobs.md", "https://cronmissed.com/learn/check-if-a-cron-job-is-running.md", "https://cronmissed.com/learn/what-is-a-cron-job.md", "https://cronmissed.com/guides/linux-crontab.md", "https://cronmissed.com/tools/cron-generator.md"]
---

# How to create a cron job on Linux and Ubuntu

> **For AI agents:** the complete index of CronMissed pages is [llms.txt](https://cronmissed.com/llms.txt). Every page is also served as markdown at its URL plus .md.

Create a cron job in five steps: test the command, open crontab -e, add one line, save, and check it with crontab -l. Includes the root crontab and removal.

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 -e` opens 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 -l` prints the file as installed.

```
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1
```

That 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](https://cronmissed.com/learn/cron-syntax-cheat-sheet.md), and the [cron expression translator](https://cronmissed.com/tools/cron-explainer.md) 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.log
```

When `/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](https://cronmissed.com/learn/cron-job-not-running.md), and see [how to check whether a cron job ran](https://cronmissed.com/learn/check-if-a-cron-job-is-running.md).

## 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](https://cronmissed.com/learn/list-all-cron-jobs.md) lists every place a job can live.

## How do you edit, disable and remove a cron job?

- **Edit:** `crontab -e` and 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 -r` deletes your whole crontab at once, with no confirmation. `crontab -i -r` asks first, and `crontab -l > backup.txt` saves 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-2d4f8a7e3c10
```

Create a check with the same schedule and CronMissed alerts you when the request is late. The [crontab guide](https://cronmissed.com/guides/linux-crontab.md) shows the setup, and [what is cron job monitoring?](https://cronmissed.com/learn/cron-job-monitoring.md) explains why a silent job needs one.

## Questions

### How do I create a cron job in Ubuntu?

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.

### Do I need to restart cron after editing the crontab?

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.

### Why does my cron job work in the terminal but not from cron?

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](https://cronmissed.com/learn/cron-environment-and-path.md) goes through the causes.

### How do I create a cron job that runs every 5 minutes?

Use `*/5 * * * *` as the schedule. Make sure a run can finish within 5 minutes, or two runs will overlap; see [overlapping cron runs](https://cronmissed.com/learn/overlapping-cron-runs.md).

## Sources

- [crontab(5) manual page](https://man7.org/linux/man-pages/man5/crontab.5.html), read 26 November 2026
- [crontab(1) manual page](https://man7.org/linux/man-pages/man1/crontab.1.html), read 26 November 2026

## Related pages

- [Cron syntax cheat sheet](https://cronmissed.com/learn/cron-syntax-cheat-sheet.md)
- [Where cron jobs are stored](https://cronmissed.com/learn/list-all-cron-jobs.md)
- [Check if a cron job ran](https://cronmissed.com/learn/check-if-a-cron-job-is-running.md)
- [What is a cron job](https://cronmissed.com/learn/what-is-a-cron-job.md)
- [Linux crontab](https://cronmissed.com/guides/linux-crontab.md)
- [/tools/cron-generator](https://cronmissed.com/tools/cron-generator.md)

## Related

- [Cron monitoring explained: concepts and fixes](https://cronmissed.com/learn.md)
- [Cron syntax cheat sheet: fields and examples](https://cronmissed.com/learn/cron-syntax-cheat-sheet.md)
- [Where cron jobs are stored and how to list them](https://cronmissed.com/learn/list-all-cron-jobs.md)
- [How to check if a cron job is running or ran](https://cronmissed.com/learn/check-if-a-cron-job-is-running.md)
- [What is a cron job? A plain explanation](https://cronmissed.com/learn/what-is-a-cron-job.md)
- [Monitor Linux crontab jobs with curl](https://cronmissed.com/guides/linux-crontab.md)
- [Crontab generator and cron dialect converter](https://cronmissed.com/tools/cron-generator.md)
