Linux online course

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.

CharacteristicUser crontabSystem crontab
Management methodManaged with crontab, such as crontab -eManaged through system configuration, such as /etc/crontab
Username fieldAbsentUsually present
Execution identityThe account that owns the crontabThe username specified in the entry
Typical permissionsA user can manage their own tableUsually 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.

CommandPurposeEffect on existing crontabNotes
crontab -eEdit the current user's crontabUpdates it when saved and installedUse the managed editor rather than editing spool files
crontab -lList the current user's entriesNo changeUseful before editing, replacing, or removing jobs
crontab -rRemove the current user's crontabDeletes every entryConfirm or back up first
crontab FILEInstall a prepared fileReplaces the complete current crontabThe file must contain every entry that should remain
crontab -u USER -lList another user's crontabNo changeRequires 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 positionField nameTypical valuesMeaning
1Minute059Minute within the hour
2Hour023Hour of the day
3Day of month131Calendar day
4Month112Month of the year
5Day of weekOften 07Day of the week; implementations commonly use both 0 and 7 for Sunday
6 onwardCommandA shell command and its argumentsThe 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:

  • 0 means one exact value.
  • 1,15 means two selected values.
  • 1-5 means every value in a range.
  • */10 means every tenth permitted value.
  • 0 9 * * 1-5 runs 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:

  • 0 is minute zero.
  • 22 is 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

  1. Save the current table to a text file:
crontab -l > my-crontab-backup
  1. 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
  1. Review the complete file, then install it:
crontab my-crontab-new
  1. 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

  • cron is the scheduling service; a cron job is one scheduled command entry.
  • crontab -e edits and installs the current user's table.
  • crontab -l lists the current user's installed entries.
  • crontab -r removes the user's entire table.
  • crontab FILE replaces 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/crontab is a system-level configuration and commonly has an additional username field.
  • Do not edit files under the cron spool directly.