Editing cron safely requires using crontab -e for personal jobs, sudo crontab -u USER -e for another user’s jobs, and editing /etc/crontab as root for system-wide tasks.
Most guides on how to edit cron skip the critical difference between user crontabs and system-wide files—and that difference is what causes jobs to silently stop running. The short version: crontab -e opens your personal schedule, sudo crontab -u USER -e edits another user’s schedule with the right permissions, and a root-level text editor on /etc/crontab handles system jobs. Each method writes to a different file, and mixing them up is the most common reason cron jobs vanish.
This article walks through every safe method, the field syntax you need to get right, and the mistakes that trip up even experienced sysadmins.
What Is Cron And How Do You Edit It?
Cron is the time-based job scheduler built into every Unix-like operating system. Scheduled tasks are called cron jobs, and they live in files called crontabs. Editing cron means editing one of these crontab files—but which file depends on whose job you’re changing and whether the task is user-specific or system-wide.
There are three distinct editing scenarios, and each uses a different command or path:
- Your own user jobs — use
crontab -e - Another user’s jobs — use
sudo crontab -u USER -e - System-wide jobs — edit
/etc/crontabor files inside/etc/cron.d/as root
Never edit the spool files under /var/spool/cron directly. Cron can ignore a manually edited spool file, and you can break the permission structure that cron relies on.
Editing Cron Jobs Safely: Commands That Work
Your personal crontab is the one you should edit most often, and crontab -e is the only safe command for the job. It opens your crontab in the system’s default text editor, validates the syntax when you save, and installs the new file into the right spool location.
Follow this sequence every time:
- Check what’s already scheduled. Run
crontab -lto list your current jobs. This confirms you’re looking at the right user account and shows you the existing entries before you make changes. - Back up the current crontab. Run
crontab -l > my-crontab-backup.txt. If a syntax error breaks your schedule, you can restore from this file withcrontab my-crontab-backup.txt. - Open the editor. Run
crontab -e. It opens whatever editor is set in theEDITORorVISUALenvironment variable — typicallyviby default, ornanoif you’ve configured it. To force a specific editor, set the variable beforehand:EDITOR=nano crontab -e. - Add or edit your job lines. Each line follows the five-field format, then the command. Save and exit the editor normally.
- Confirm the new schedule. Run
crontab -lagain. If you see your changes listed and no error messages appeared on save, your cron jobs are live.
Cron Field Syntax Reference
| Field | Allowed Values | Example |
|---|---|---|
| Minute | 0–59 |
30 = half past the hour |
| Hour | 0–23 |
14 = 2 PM |
| Day of month | 1–31 |
15 = the 15th |
| Month | 1–12 or JAN–DEC |
6 or JUN |
| Day of week | 0–6 or SUN–SAT (0 and 7 both mean Sunday in most implementations) |
0 or SUN |
| Wildcard | * |
* in minute field = every minute |
| Step values | /N |
*/15 in minute field = every 15 minutes |
| Lists and ranges | , and - |
1-5 = weekdays; 1,15 = 1st and 15th |
The most common gotcha: when both the day-of-month and day-of-week fields contain a value other than *, most cron implementations treat them as an OR condition — the job runs when either field matches. If you want “every Monday AND the 1st of the month,” you need two separate job lines.
How Do You Edit Another User’s Crontab?
Editing another user’s cron jobs requires administrative privileges. The safe command is sudo crontab -u USERNAME -e, where USERNAME is the account you want to edit. This command validates and installs the crontab the same way your own crontab -e does, but under the target user’s identity.
Without the -u flag, crontab -e always edits the current user’s own crontab — even when run with sudo. The -u flag is what tells cron which user’s schedule to open.
After saving, run sudo crontab -u USERNAME -l to verify the changes. If the output matches what you entered, the new jobs are active under that user’s identity.
Editing System-Wide Cron Jobs
System-wide jobs belong in /etc/crontab or in drop-in files under /etc/cron.d/. These files require root access and use a slightly different format: they include a username field between the day-of-week field and the command. This field tells cron which system user should run the command.
For example, a system-wide backup job might look like:
0 2 * * * root /usr/local/bin/backup.sh
That extra root field is what distinguishes system crontabs from user crontabs. User crontabs don’t have it because crontab -e already knows which user the job belongs to. Editing /etc/crontab directly is appropriate for maintenance tasks that should run regardless of which user accounts exist on the system. The Oracle Solaris documentation confirms that the crontab -e approach is the simplest way to create and edit user crontab files, while system-wide files require direct editing with root privileges.
Common Mistakes That Break Cron Jobs
Even a correct cron command won’t run if it’s in the wrong file, uses the wrong syntax, or runs in an empty environment. The table below covers the most frequent failures and how to avoid them.
| Mistake | What Happens | Fix |
|---|---|---|
Editing /etc/crontab for a user job |
Job never runs because cron reads a different file for the user. | Use crontab -e for personal jobs; /etc/crontab is for system-wide tasks. |
| Wrong field order | Command runs at the wrong time or never. | Remember the order: minute, hour, day of month, month, day of week, command. |
| Missing absolute path in command | Job appears to run but produces no result because cron’s PATH is minimal. |
Use full paths like /usr/bin/backup.sh instead of backup.sh. |
| Both day fields set to a value | Job runs more often than expected (OR condition). | Use separate lines if you need AND logic, or use a script to check both conditions. |
Editing /var/spool/cron directly |
Cron ignores the file or permissions break. | Always use crontab -e — it’s the only safe path to user crontabs. |
| Not backing up before editing | Deleting a line accidentally loses the entire schedule. | Run crontab -l > backup.txt before every edit session. |
The Safe Order Of Operations For Cron Edits
- Identify the scope. Is this job for you, another user, or the whole system? Pick the right command or file before touching anything.
- Back up the existing crontab. A single recovery file saves hours of reconstruction.
- Use the correct command.
crontab -efor personal jobs,sudo crontab -u USER -efor another user, root editor on/etc/crontabfor system jobs. - Verify syntax with a dry run.
crontab -lafter saving confirms your changes are installed and active. - Test the new job. Let it run once, then check logs or output to confirm it executes as expected.
Following that sequence eliminates nearly every cron editing failure. The one remaining rule: always use absolute paths and export needed environment variables inside the job script itself, because cron runs in a stripped-down shell with a short PATH.
References & Sources
- Oracle. “Solaris Administration: How to Create a Crontab File” Documents the
crontab -ecommand and user crontab editing workflow.
