Managing User Cron Jobs in Linux
Learn to create, edit, view, install, back up, and remove per-user Linux cron jobs with crontab.
Cron is a scheduling service that runs commands automatically at configured times or intervals. A scheduled command is called a cron job. Linux users can manage personal scheduled jobs with the crontab command without changing the system-wide cron configuration.
This lesson assumes basic shell commands, Linux users and permissions, text editor operation, absolute paths, and shell wildcard behavior. For background, see managing file ownership and the Linux file structure.
User Cron Jobs and System Cron Jobs
A user crontab is a table of scheduled commands owned by one account. Every command in that table runs with the identity and permissions of its owner. For example, a job in Bob's crontab runs as Bob, not as root.
System-wide cron configuration is intended for administrators and services. A common system configuration file is /etc/crontab. It usually includes a username in every entry so that the system can choose which account runs the command.
| Characteristic | User crontab | System crontab |
|---|---|---|
| Management method | Managed with crontab, such as crontab -e | Managed through system configuration, such as /etc/crontab |
| Username field | Absent | Usually present |
| Execution identity | The account that owns the crontab | The username specified in the entry |
| Typical permissions | A user can manage their own table | Usually requires administrative access |
The username field is omitted from a user crontab because the owner is already known. A user entry has five time fields followed immediately by the command. Do not copy the six-field format from /etc/crontab into a personal crontab.
The crontab Command
crontab refers both to the command-line utility used to manage scheduled entries and to the table of entries that it manages. Its general form is:
crontab [-u USER] [OPTIONS] [FILE]
Without -u, an operation normally affects the current user's crontab. The -u USER option selects another user's table, but listing or changing another user's crontab generally requires appropriate administrative privileges.
| Command | Purpose | Effect on existing crontab | Notes |
|---|---|---|---|
crontab -e | Edit the current user's crontab | Updates it when saved and installed | Use the managed editor rather than editing spool files |
crontab -l | List the current user's entries | No change | Useful before editing, replacing, or removing jobs |
crontab -r | Remove the current user's crontab | Deletes every entry | Confirm or back up first |
crontab FILE | Install a prepared file | Replaces the complete current crontab | The file must contain every entry that should remain |
crontab -u USER -l | List another user's crontab | No change | Requires authorization in typical configurations |
Editing a User Crontab
Open the current user's crontab with:
crontab -e
The command opens an editor selected by system or environment configuration. It may be nano, vi, vim, or another editor. Add or change entries, then save the file and exit the editor. The crontab command validates and installs the updated table when the editor closes successfully.
If the editor is unfamiliar, learn its save and exit commands before making changes. In nano, for example, Ctrl+O writes the file and Ctrl+X exits. The exact editor and behavior can vary.
User Crontab Entry Format
Each active user-crontab entry contains five scheduling fields followed by the command:
minute hour day-of-month month day-of-week command
| Field position | Field name | Typical values | Meaning |
|---|---|---|---|
| 1 | Minute | 0–59 | Minute within the hour |
| 2 | Hour | 0–23 | Hour of the day |
| 3 | Day of month | 1–31 | Calendar day |
| 4 | Month | 1–12 | Month of the year |
| 5 | Day of week | Often 0–7 | Day of the week; implementations commonly use both 0 and 7 for Sunday |
| 6 onward | Command | A shell command and its arguments | The command cron runs |
A wildcard, written as *, means every permitted value for that field. Other useful forms include exact values, comma-separated lists, ranges, and step values:
0means one exact value.1,15means two selected values.1-5means every value in a range.*/10means every tenth permitted value.0 9 * * 1-5runs at 09:00 on weekdays.*/15 * * * *runs every 15 minutes.
Use spaces to separate fields. A user crontab does not contain a separate account column:
# Correct in a user crontab
0 9 * * 1-5 /home/bob/bin/report.sh
# This has a system-crontab-style username field and is not correct here
0 9 * * 1-5 bob /home/bob/bin/report.sh
Example: Run a Cleanup Job Daily at 22:00
This entry schedules a cleanup command for 22:00 every day:
0 22 * * * rm /home/bob/trash/*
Read it from left to right:
0is minute zero.22is hour 22, or 10:00 PM in the 24-hour clock.- The three
*fields mean every day of the month, every month, and every day of the week. rm /home/bob/trash/*is the command portion. It attempts to remove the matching entries in that directory.
Because this is a user crontab, there is no bob account field. If Bob installs the entry, cron runs it as Bob. The command also uses an absolute path, which is safer than relying on cron's limited environment and current directory.
Viewing Installed Cron Jobs
List the current user's installed entries with:
crontab -l
This is useful for checking whether an edit was installed and for reviewing jobs before making a broad change. If the account has no personal crontab, the command may report that no crontab exists. Create one with crontab -e, save an entry, and run crontab -l again.
When authorized, an administrator can inspect another user's table with:
crontab -u USER -l
Removing a User Crontab
Remove the current user's entire crontab with:
crontab -r
This removes all scheduled entries for the account, not just one job. It is not a command for deleting a single line. List or back up the table first:
crontab -l
Some implementations provide an interactive confirmation option for removal. Check the local manual page if you need confirmation behavior, but always treat crontab -r as a complete-table deletion operation.
Installing a Crontab from a File
A prepared plain-text file can be installed as the current user's complete crontab:
crontab my-jobs.cron
Installation replaces the existing crontab. If my-jobs.cron contains only a new job, previously installed jobs disappear. The file must contain every entry that should remain.
Safe backup and replacement workflow
- Save the current table to a text file:
crontab -l > my-crontab-backup
- Make a copy of the backup and edit the copy, preserving all desired entries:
cp my-crontab-backup my-crontab-new
# Edit my-crontab-new with your preferred text editor
- Review the complete file, then install it:
crontab my-crontab-new
- Confirm the installed result:
crontab -l
If a replacement goes wrong, reinstall the backup file with crontab my-crontab-backup.
Storage and Administration Boundaries
Installed user crontabs are commonly stored in a cron spool location such as /var/spool/cron/, although the exact directory and file layout vary by distribution and cron implementation. The cron spool is system-managed storage for installed user tables.
Do not edit spool files directly, even when you have administrative access. Direct editing may skip syntax validation, create incorrect ownership or permissions, and fail to trigger the expected reload or notification behavior. Use crontab -e for interactive changes or crontab FILE for a complete prepared table.
Troubleshooting User Cron Jobs
The job runs under the wrong account
Check which account owns the table and run crontab -l as that account. A user crontab always runs commands as its owner. Do not expect a username field to change the execution identity; that field belongs to system-crontab syntax.
The entry contains a username
Remove the username from a user crontab. The format must contain five scheduling fields followed directly by the command. For example, use 0 9 * * 1-5 /home/bob/bin/report.sh, not an entry with bob between the schedule and command.
Existing jobs disappeared
crontab FILE replaces the entire current table. Restore the backup or create a new file containing both the old entries and the new entries, then install that complete file.
crontab -l says no crontab exists
The current account probably has not installed any personal entries. Use crontab -e, add a valid entry, save and exit, and then list the table again.
A cleanup job deletes too much
Inspect the target with a non-destructive listing command before using rm. Check absolute paths and wildcard expansion carefully. Use explicit paths where practical, avoid automating unverified deletion, and protect important data with backups.
Direct spool edits behave unreliably
Cron spool files are implementation-managed. Replace manual edits with crontab -e or a validated installation using crontab FILE.
Exam-Relevant Notes
cronis the scheduling service; a cron job is one scheduled command entry.crontab -eedits and installs the current user's table.crontab -llists the current user's installed entries.crontab -rremoves the user's entire table.crontab FILEreplaces the complete current crontab with the file's contents.- User crontab entries have five time fields and then a command; they do not have a username field.
- Commands in a user crontab run as the account that owns the table.
/etc/crontabis a system-level configuration and commonly has an additional username field.- Do not edit files under the cron spool directly.