Cron Guides
Guides

Editing crontab and environment variables: PATH, shell, user

crontab -e, environment differences, system vs. user crontab

You usually edit jobs with crontab -e. This command opens the current user's own crontab, and when you save it, it checks the syntax before applying. List them with crontab -l and delete them all with crontab -r, but be careful because -r deletes without confirmation.

The environment in which cron runs a job is different from the shell you log in with. cron provides only a minimal environment, and even the PATH is usually as short as /usr/bin:/bin. That's why a command that worked in your login shell often fails in cron with 'command not found'. It's safer to write commands with absolute paths.

You can declare environment variables at the top of the crontab file. Commonly used ones are PATH=/usr/local/bin:/usr/bin:/bin, SHELL=/bin/bash, MAILTO="you@example.com", and CRON_TZ=Asia/Seoul to fix the time zone. If a value contains spaces, wrap it in quotes.

A user crontab and a system crontab have different formats. A user crontab created with crontab -e uses the standard 5 fields (minute hour day-of-month month day-of-week). System entries in /etc/crontab and /etc/cron.d/*, on the other hand, use 6 fields (minute hour day-of-month month day-of-week user command), with a run-as user field added after day of week. This tool parses the standard 5 fields, so when checking a system crontab, drop the user field and enter only the first 5 fields.

Instead of a precise time, if 'daily/hourly' is enough, you can also drop a script into a drop-in directory like /etc/cron.daily or /etc/cron.hourly. They run on a fixed cadence without an expression. Keeping crontab for only the cases that need a specific minute or time — using an expression built with this tool — makes management cleaner.

Resources

Schedule collection

Copy-and-go recipes

Syntax cheat sheet

The 5 fields and special characters at a glance

Macros & aliases

Shorthand expressions like @daily

Guides

Practical guides to truly understand cron and make fewer mistakes