A cron job in Linux is a scheduled shell command that runs automatically at fixed intervals, defined by a five-field expression inside a crontab file. The five fields appear in the order minute, hour, day of month, month, and day of week, and each accepts numbers, ranges, wildcards, or step values such as */15 for every 15 minutes. You create a cron job by writing that expression, appending the command you want executed, and saving the line in the right crontab so the cron daemon picks it up. The hard part is rarely the command itself; it is choosing field values that match the schedule you actually want without forgetting which column is the month and which is the weekday. A Cron Expression Generator maps seven common presets, every minute, every N minutes, hourly, daily, weekdays, weekly, and monthly, to standard crontab fields so you describe the schedule in plain English and copy the result. After that, you only need to drop the line into your per-user crontab or a system-wide file and confirm the scheduler's time zone.

how to create a cron job in linux
how to create a cron job in linux

What a Linux Cron Job Actually Contains

A crontab entry is just two pieces glued together by whitespace: a schedule expression and a shell command. The schedule is the five-field cron expression, and the command can be a single executable path, a script invocation, or a piped shell pipeline. The cron daemon re-reads the crontab when it starts, when a user runs crontab -e, and at periodic reload intervals, so edits take effect without rebooting the server.

Each user can hold their own crontab, and root can edit system-wide schedules inside /etc/crontab or drop files into /etc/cron.d. The expression itself describes timing only; it does not carry the command, the working directory, environment variables, retries, locking, or monitoring. All of that has to live in the command you append after the five fields, which is why a wrapper script is often the safest place to put real logic and to log the result.

The Five-Field Cron Expression in Plain English

The five fields, in the exact order traditional crontab requires, are minute, hour, day of month, month, and day of week. The generator keeps minutes between 0 and 59, hours between 0 and 23, weekdays between Sunday 0 and Saturday 6, and month days between 1 and 31, so you cannot enter an out-of-range value by accident. The table below summarizes the canonical ranges and a short example for each.

PositionFieldRangeExampleMeaning
1Minute0-59*/15Every 15 minutes
2Hour0-239At 9 a.m.
3Day of month1-311On the first day
4Month1-12*Every month
5Day of week0-6 (0 and 7 = Sunday)1-5Monday through Friday

An asterisk in any field means every valid value for that field, so * in the hour column runs every hour. A comma lists specific values, a hyphen defines an inclusive range, and a slash introduces a step. The weekday range 1-5 covers Monday through Friday in the canonical Unix numbering, and the implementation follows the standard crontab(5) syntax documented in the Linux man-pages crontab(5) reference.

Build the Schedule with Cron Expression Generator

The fastest way to get a correct five-field expression for the schedule you want is to use the Cron Expression Generator, which maps bounded schedule presets to the standard crontab fields. Open the tool and follow these steps.

  1. Choose the schedule type that matches the job frequency from the seven presets: every minute, every N minutes, hourly, daily, weekdays, weekly, or monthly.
  2. Set the interval, minute, hour, weekday, or month day shown for that schedule, since the relevant control appears only for the preset you picked and the generated expression plus a plain-English summary update immediately.
  3. Copy the five-field expression and verify it in the target scheduler and time zone before adding the command.

The presets intentionally avoid setting both day-of-month and day-of-week at the same time, because that combination triggers implementation-specific OR behavior that can produce unexpected matches on some cron implementations. Generation happens locally and no command or schedule is uploaded, so the only thing that leaves your browser is the expression string you copy.

Symbols You Will See in the Generated Expression

The generator uses only wildcard, step, fixed-value, and inclusive weekday-range syntax documented by crontab(5), which keeps the output compatible with traditional Unix-style crontab entries on Linux.

SymbolMeaningExampleResult
*Every valid value in the field*Every minute (in the minute field)
,List of values0,30At minutes 0 and 30
-Inclusive range1-5Monday through Friday
/Step value*/10Every 10 minutes

Because the generator restricts itself to those four syntax forms, you can paste the result into a standard Linux crontab without translation. If you later want to confirm that the line will fire at the times you expect, run it through the Cron Parser to see the next few matching timestamps for the same expression.

Common Pitfalls in Linux Cron Jobs

Even with a correct expression, several Linux-specific behaviors trip people up on the first deployment. Watch for these before relying on the schedule.

  • Cron runs in the scheduler's configured time zone, not necessarily the time zone shown on your workstation. Check /etc/timezone or the TZ value the daemon was started with.
  • Daylight-saving transitions can skip or repeat local wall-clock times, so a job scheduled at 2:30 a.m. on a spring-forward Sunday may never run that day.
  • A monthly job scheduled for day 29, 30, or 31 is silently skipped in months that do not contain that date, which makes February the usual culprit.
  • The expression only describes timing, so it does not include retries, locking, or monitoring. Use an idempotent command, write failures to a log file, and protect against overlapping runs if the job can outlast its interval.

Adding the Expression to Your Linux Crontab

A safe workflow is to choose the schedule in the generator, copy the five-field expression, and only then add the command in the target crontab. To edit the current user's crontab, run crontab -e in a shell; to edit root's crontab, use sudo crontab -e. To drop a system-wide line, place a file inside /etc/cron.d/ or add it to /etc/crontab, which uses a slightly different six-field format that includes the user.

The general form is the five fields, then the command:

<minute> <hour> <day> <month> <weekday> /path/to/command args

For example, after selecting "every weekday at 09:30" in the generator you might paste:

30 9 * * 1-5 /opt/backup/run.sh >> /var/log/backup.log 2>&1

That line runs the backup script at 09:30 on Monday through Friday and appends both stdout and stderr to a log file. Test the command manually first, deploy it in a non-production environment, confirm the scheduler's time zone, and only then promote it.

Confirm the Target Scheduler Before Deploying

Some hosted schedulers add seconds, years, question marks, or vendor-specific syntax on top of the standard five fields, so confirm that your target accepts standard five-field cron before deploying it. Cronie's implementation, documented at cronie-crond/cronie crontab(5), is the reference most modern Linux distributions follow, and it accepts exactly the syntax the generator produces. If you are deploying to a managed platform that expects a six-field Quartz expression instead, swap to a Quartz-specific builder rather than forcing the five-field output into a slot that needs a seconds column.