CCronExplain
Get CronExplain

CronExplain/Guides

How to Create a Crontab Entry in Linux

Learn how to edit your crontab file, understand field syntax, and verify your schedule works using a visual builder and next-fire preview.

October 10, 2026 · 4 min read

To create a crontab entry in Linux, open your terminal and type crontab -e to launch your default editor. Enter a schedule using the five-field syntax (minute, hour, day, month, weekday) followed by the command you want to run, then save and exit. This registers the task to run automatically in the background.

Understanding the Crontab File Structure

The crontab file is a plain-text list of scheduled commands. Unlike other configuration files, it does not require a specific header or complex YAML structure. Each line represents one independent job. The format is strict but simple: five time fields followed by a command. Spaces between fields are required, but leading spaces on the line itself are ignored. Comments start with a hash symbol (#) and are useful for documenting why a job exists, especially when multiple jobs share similar schedules.

You edit this file by running crontab -e. This opens the file in the editor defined by your $EDITOR environment variable. If you have not set one, it usually defaults to nano or vi. Changes take effect immediately upon saving; you do not need to restart the cron service for new entries to be recognized.

Editing Your Crontab with nano or vim

When you run crontab -e, the interface depends on your system’s default editor. Most modern distributions default to nano, which is beginner-friendly because it displays key shortcuts at the bottom of the screen. To save changes in nano, press Ctrl+O, confirm the filename if prompted, and press Enter. Exit with Ctrl+X.

If your system uses vim, the process is slightly different. Press i to enter insert mode and type your entry. Press Esc to leave insert mode, then type :wq and press Enter to write and quit. If you make a mistake and want to exit without saving, press Esc and type :q!.

For users who prefer a graphical interface or want to avoid memorizing keystrokes, CronExplain offers a visual builder. You can select dropdown values for minute, hour, and weekday to construct the expression without memorizing syntax. This reduces typos and ensures the schedule logic is correct before you paste it into your terminal.

Breaking Down the Five-Field Syntax

Every cron entry follows this order: Minute Hour Day Month Weekday Command. Each field accepts specific values, ranges, and lists. Understanding what each position controls prevents common scheduling errors.

FieldRangeDescriptionExample ValueMeaning
Minute0-59Minutes past the hour0On the hour
Hour0-23Hour of the day (24h)99 AM
Day1-31Day of the month*Every day
Month1-12Month of the year*Every month
Weekday0-7Day of week (Sun=0)1Monday

Special characters modify how these fields work. An asterisk (*) means "every value." A comma-separated list (1,15,30) runs the job at those specific points. A slash (*/5) means "every 5 units." Combining these allows precise control. For example, */15 9-17 * * 1-5 runs every 15 minutes between 9 AM and 5 PM on weekdays.

Worked Example: Weekly Backup Script

Suppose you need a backup script to run every Monday at 9:00 AM. You need to translate this requirement into the five-field syntax.

  1. Minute: The job starts exactly on the hour, so the minute is 0.
  2. Hour: The time is 9 AM, so the hour is 9.
  3. Day: It runs every Monday regardless of the date, so the day field is *.
  4. Month: It runs every month, so the month field is *.
  5. Weekday: Monday is represented by 1 (Sunday is 0).

Combine these into the expression: 0 9 * * 1. Append your command after the fields. If your backup script is located at /home/user/backup.sh, the full line looks like this:

0 9 * * 1 /home/user/backup.sh

Paste this into your crontab editor. If you are unsure about the weekday number, you can verify it by checking that Monday is indeed 1. Some systems allow Mon as a text abbreviation, but numeric values are universally supported.

Verifying Next Fire Times Before Saving

A common mistake is assuming the schedule works as intended without testing it. You can verify the logic by checking the next few execution times. This is particularly useful when using complex combinations of ranges and steps.

For the expression 0 9 * * 1, the system calculates the next ten times it will fire. In a standard environment, the output would look like this:

Monday, October 2, 2023, 9:00 AM
Monday, October 9, 2023, 9:00 AM
Monday, October 16, 2023, 9:00 AM
Monday, October 23, 2023, 9:00 AM
Monday, October 30, 2023, 9:00 AM
Monday, November 6, 2023, 9:00 AM
Monday, November 13, 2023, 9:00 AM
Monday, November 20, 2023, 9:00 AM
Monday, November 27, 2023, 9:00 AM
Monday, December 4, 2023, 9:00 AM

Notice that weekends are skipped correctly. If you see Saturday or Sunday in the list, your weekday field is incorrect. Using a tool that provides this preview helps catch errors early. For instance, if you accidentally typed 0 9 * * *, the preview would show daily executions, alerting you that the weekday constraint was missing.

Common Pitfalls: Timezones and Missing Paths

Two issues cause most cron failures: incorrect timezone assumptions and missing environment variables. Cron runs with a minimal environment, meaning it does not always load your shell profile or .bashrc. This can lead to errors when your script relies on specific paths or variables.

To avoid path issues, always use absolute paths in your command. Instead of backup.sh, use /home/user/scripts/backup.sh. If your script depends on other scripts or binaries, ensure their paths are fully qualified or set within the script itself.

Timezones can also be tricky. Cron typically uses the system timezone. If your server is in UTC but you want backups at 9 AM EST, the cron entry must account for this offset. You can check your server’s timezone by running date. If the server time differs from your local time, adjust the hour field accordingly. For example, if the server is UTC and you want 9 AM EST (UTC-5), you might need to schedule the job for 14 instead of 9, depending on daylight saving rules. Always verify the server’s current time with date before finalizing your schedule.

Do it in CronExplain

Everything in this guide works in the browser — open the tool and try it on your own input.

Open CronExplain →

Questions people also ask

Where is the crontab file located?

User-specific crontabs are typically stored in `/var/spool/cron/crontabs/` or `/var/spool/cron/`, while system-wide configurations reside in `/etc/crontab` or `/etc/cron.d/`. The exact path depends on your Linux distribution and whether you are editing a user-specific or system-wide schedule.

How do I list my current cron jobs?

Run `crontab -l` in your terminal to display all scheduled jobs for the current user. If you need to view jobs for a different user, append their username to the command, such as `crontab -l -u username`.

Does cron run in UTC or local time?

Cron runs in the system's configured local time zone, not necessarily UTC. You can verify the active time zone by checking the `/etc/timezone` file or running the `timedatectl` command, which determines how cron interprets hour and minute fields.

How do I delete a cron job?

Open the editor with `crontab -e`, locate the specific line you want to remove, and delete it before saving and exiting. Alternatively, you can clear all jobs for the current user instantly by running `crontab -r`, though this removes every entry without confirmation.

More guides