Blog · WebJi® India

Crontab examples for Linux

Quick answer: A Linux crontab example is one line: five time fields, then the command. Those fields are minute, hour, day of month, month, and weekday. The line */15 * * * * /usr/bin/php /home/user/cron.php runs that PHP file every 15 minutes. crontab -e saves the line for the user who is logged in.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Stacked hard drives in a secure storage room with one drive glowing

What do the five Linux crontab fields mean?

A Linux crontab line has five time fields and then the command. Crond compares those fields with the server clock once a minute and runs the command when they match. There is no seconds field on a normal user crontab.

FieldAllowed valuesA star means
Minute0–59Every minute
Hour0–23Every hour
Day of month1–31Every date
Month1–12, or jan–decEvery month
Weekday0–7 (0 and 7 are Sunday)Every day of the week

The star means every allowed value in that field. A comma lists values, so 8,20 in the hour field is 08:00 and 20:00. A hyphen is a range, so 1-5 in the weekday field is Monday through Friday. A slash is a step: */15 in the minute field is minute 0, 15, 30, and 45.

  • Star: every allowed value in that field.
  • Comma: a list, such as 8,20 for 08:00 and 20:00.
  • Hyphen: a range, such as 1-5 for Monday to Friday.
  • Slash: a step, such as */15 for every 15 minutes.

Month and weekday fields also accept names, such as jan or mon. Sunday is 0 or 7. Monday is 1 and Saturday is 6. The clock is the server clock. If date prints UTC, 02:00 in the crontab is 07:30 IST.

If both the day-of-month and the weekday are restricted, Vixie cron and cronie run the job when either field matches. The line 0 6 1 * 1 runs at 06:00 on the 1st and also on every Monday. A star in either field turns that rule off.

Those five fields are the same schedule described in what a cron job is. The lines below are the ones you paste.

Which crontab examples run every few minutes?

Short intervals belong in the minute field. A star in every field runs every minute, which is rarely what a website needs. A step or a list is the usual line.

Crontab lineWhen it runs
* * * * * /usr/bin/php /home/user/cron.phpEvery minute
*/5 * * * * /usr/bin/php /home/user/cron.phpEvery 5 minutes
*/15 * * * * /usr/bin/php /home/user/cron.phpEvery 15 minutes
*/30 * * * * /usr/bin/php /home/user/cron.phpEvery 30 minutes, at :00 and :30
0 * * * * /usr/bin/php /home/user/cron.phpMinute 0 of every hour
15 * * * * /usr/bin/php /home/user/cron.php15 minutes past every hour
0 9-17 * * 1-5 /usr/bin/php /home/user/cron.phpMinute 0, from 09:00 through 17:00, Monday to Friday

0 9-17 * * 1-5 is not a job that stays running from 09:00 to 17:00. It starts once at minute 0 of each of those hours, Monday to Friday, and then exits. Put the long work inside the script.

Use the full path to the program. php alone is resolved with cron's PATH, which is often only /usr/bin:/bin, so the shell you use when logged in can find a binary that cron cannot.

Which crontab examples run daily, weekly, or monthly?

Daily, weekly, and monthly lines still use the same five fields. Set the hour and the day, and leave the minute at 0 unless the job needs a different minute.

Stacked hard drives in a secure storage room with one drive glowing
Crontab lineWhen it runs
15 3 * * * /home/user/scripts/backup.sh03:15 every day
30 0 * * * /usr/local/bin/cleanup.sh00:30 every day
0 8,20 * * * /home/user/scripts/sync.sh08:00 and 20:00 every day
0 2 * * 6 /home/user/scripts/weekly.shSaturday at 02:00
0 4 * * 0 /home/user/scripts/report.shSunday at 04:00
0 1 1 * * /home/user/scripts/monthly.sh01:00 on the 1st of the month
0 0 1 1 * /home/user/scripts/yearly.sh00:00 on 1 January

A backup that only copies files is not a restore test. After the 03:15 job, check that the archive exists and that the disk still has room. The checks for free disk space on a Linux server are the next step when the dump grows every night.

A job does not run late if the server was off at that minute. The next matching minute is the next chance. The @reboot shortcut below is the boot case, not a catch-up for a missed 03:15.

What do @daily and @reboot mean in crontab?

Shortcuts replace the five fields. They do not change the command. @daily is midnight, which is 0 0 * * *, and @hourly is minute 0 of every hour.

ShortcutSame as
@rebootOnce when crond starts after boot
@yearly or @annually0 0 1 1 *
@monthly0 0 1 * *
@weekly0 0 * * 0 (Sunday)
@daily or @midnight0 0 * * *
@hourly0 * * * *

@reboot runs once per boot. It does not repeat, and it does not replay a schedule the machine missed while it was down. On a shared hosting account, test it, because some panels never fire @reboot.

Cron is not a retired tool. systemd timers are a separate scheduler with their own unit files. A user crontab is still the file crontab -e edits.

How do you log or email crontab output?

Cron mails the command's standard output and standard error to the crontab user unless you redirect them. An empty mailbox means the command printed nothing. It does not mean the command succeeded.

Append output with /home/user/scripts/backup.sh >> /home/user/logs/cron.log 2>&1. Create the logs directory first. A missing directory makes the redirect fail before the script runs.

MAILTO=you@example.com on its own line sends that mail to another address, if the server can deliver mail. An empty MAILTO= drops the mail for every job in that file. Set the empty value only when the log file is already in place.

On a VPS, the daemon's own line is separate from the script log. Debian and Ubuntu write it to /var/log/syslog. AlmaLinux and other cronie systems use /var/log/cron.

journalctl -u cron or journalctl -u crond shows the same start line. That line proves crond launched the command. It does not prove the script finished.

Why does a Linux crontab job fail with no mail?

A command that works in your SSH session can fail in cron because the environment is smaller. The usual default PATH is /usr/bin:/bin and the usual shell is /bin/sh, not bash.

Find the binary while logged in with command -v php or command -v python3, then paste that path into the crontab. A relative path such as scripts/backup.sh depends on the current directory, which cron does not set to your home in a reliable way.

$HOME is set. A leading tilde is not expanded in every cron. Write /home/user/scripts/backup.sh instead of a short name.

The script must be executable by the user who owns the crontab, and it must use Unix line endings. A permission denied line in the mail is the script or the directory, not the five time fields.

An unescaped percent sign in the command is special. Cron turns the first % into a newline and sends the rest to the command as input. Write date +\%Y-\%m-\%d or the format never reaches date.

A job longer than its gap can start a second copy. flock -n /tmp/backup.lock /home/user/scripts/backup.sh skips the new start while the lock is held.

If the mail is still unclear, email support@webji.services. The desk replies in Hindi and English, and the average first reply is under 60 minutes. The office phone is not a support line.

How do you list, edit, or remove a crontab?

crontab -l prints the current user's file. If the reply is no crontab for that user, nothing is scheduled yet. crontab -e opens the editor and installs the file when you save. The success line is crontab: installing new crontab.

  1. Run crontab -l and copy the file somewhere before you edit it.
  2. Run crontab -e, add one line, and save.
  3. Run crontab -l again and confirm the new line is the only change.
  4. Wait for the next matching minute and read the log or the mail.
  5. To drop one job, open crontab -e and delete that line. crontab -r removes the whole file. crontab -i asks before that delete.

crontab -u username -l lists another user's file. You need permission for that user. Root can do it. A normal hosting user cannot read someone else's crontab.

The daemon has to be running. On Debian and Ubuntu the unit is cron. On AlmaLinux and Rocky it is crond. systemctl status cron or systemctl status crond shows active or inactive. A stopped daemon means no line will fire.

On Linux hosting with SSH, this is the file you edit. A cPanel account stores the same five fields under Advanced, then Cron Jobs.

Frequently Asked Questions

How do I write a crontab example in Linux?

Open the file with crontab -e. Type five time fields, a space, and the full command, then save. crontab -l should print the line back. The next matching minute writes the log or the mail you set up.

What does */15 * * * * mean?

It runs every 15 minutes, at minute 0, 15, 30, and 45 of every hour. The slash is a step in the minute field. The other four stars mean every hour, every date, every month, and every weekday.

How do I run a cron job every 30 minutes?

Use */30 * * * * and then the command. That starts at minute 0 and minute 30 of every hour. 0,30 * * * * is the same two minutes written as a list.

How do I run a job every day at midnight?

Use 0 0 * * * and the command, or the shortcut @daily. Both mean midnight on the server clock. If date shows UTC, that midnight is 05:30 IST, not midnight in India.

What does @reboot mean in crontab?

@reboot runs the command once when crond starts after a boot. It is not a daily schedule, and it does not rerun a job the server missed while it was off. On shared hosting, confirm the panel actually fires it.

Where are Linux cron logs?

Script output goes to mail, or to the file you added with a redirect. The daemon start line is in /var/log/syslog on Debian and Ubuntu, and in /var/log/cron on cronie systems such as AlmaLinux.

How do I delete one crontab line without removing the rest?

Run crontab -e and delete only that line, then save. crontab -r deletes every line in the file. crontab -i asks you to confirm before that full delete.

Is cron outdated on Linux?

No. A user crontab is still how you schedule a command with crontab -e. systemd timers are a different system, with unit files instead of five fields.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →