How to List Cron Jobs For All Users in Linux

Published July 1, 2024

This article explains how to show cron jobs for all users and the current user on a Linux system. It covers ways to list cron jobs as a root user, view system-wide cron jobs, and check user-specific cron tasks. The article also explains how to read cron job formats and gives examples of common cron job setups.

Displaying Cron Jobs for All Users

Listing Cron Jobs as Root User

As a root user or with sudo privileges, you can view cron jobs for all users on the system. This method gives you a full view of scheduled tasks across all user accounts.

To list cron jobs for all users, use this command:

for user in $(cut -f1 -d: /etc/passwd); do echo "Crontab for $user:"; sudo crontab -u $user -l 2>/dev/null; echo; done

Example Output

Crontab for root:
0 2 * * * /usr/bin/system-backup.sh
30 3 * * 1 /usr/bin/update-packages.sh

Crontab for alice:
0 9 * * 1-5 /home/alice/scripts/daily-report.sh

Crontab for bob:
no crontab for bob

Crontab for carol:
0 0 1 * * /home/carol/scripts/monthly-cleanup.sh

Interpreting the Output

  • Each user's crontab starts with "Crontab for [username]:"
  • If a user has no cron jobs, you'll see "no crontab for [username]"
  • Each line in a user's crontab is a scheduled task
  • The format follows the standard cron job structure: minute, hour, day of month, month, day of week, followed by the command to run

Viewing System-wide Cron Jobs

System-wide cron jobs are tasks that run regardless of user login status. These are often used for system maintenance tasks.

Checking the Main System Crontab File

sudo cat /etc/crontab

Example output:

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

Examining Cron Job Directories

ls -l /etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.monthly /etc/cron.weekly

Example output:

/etc/cron.d:
total 12
-rw-r--r-- 1 root root 102 Mar 15 10:30 backup-script
-rw-r--r-- 1 root root 285 Apr  1 14:22 sysstat

/etc/cron.daily:
total 20
-rwxr-xr-x 1 root root 376 Feb 10 09:15 logrotate
-rwxr-xr-x 1 root root 249 Feb 17 11:40 man-db

/etc/cron.hourly:
total 4
-rwxr-xr-x 1 root root 392 Mar  3 18:55 update-cache

/etc/cron.monthly:
total 4
-rwxr-xr-x 1 root root 313 Jan 22 08:10 clean-old-logs

/etc/cron.weekly:
total 8
-rwxr-xr-x 1 root root 211 Apr 12 16:30 update-packages
-rwxr-xr-x 1 root root 427 Mar 28 12:45 backup-home

Viewing Contents of a Specific Cron Job File

sudo cat /etc/cron.d/backup-script

Example output:

# Perform daily system backup
0 1 * * * root /usr/local/bin/system-backup.sh

# Clean up old backups weekly
0 2 * * 0 root /usr/local/bin/cleanup-old-backups.sh

System-wide Cron Entry Format

The format of system-wide cron entries is like user crontabs, with an extra field for the user to run the job:

minute hour day month day-of-week user command

Listing Cron Jobs for the Current User

Using the crontab -l Command

To display cron jobs for the current user, use the crontab -l command in the terminal. This command shows all scheduled tasks for the logged-in user.

crontab -l

Example Output

# m h  dom mon dow   command
0 9 * * 1-5 /home/user/scripts/daily-report.sh
30 18 * * * /home/user/scripts/evening-backup.sh
0 0 1 * * /home/user/scripts/monthly-cleanup.sh

Interpreting the Output

Each line represents a scheduled job with the following format:

Field Description Example
Minute (m) 0-59 0
Hour (h) 0-23 9
Day of Month (dom) 1-31 *
Month (mon) 1-12 or JAN-DEC *
Day of Week (dow) 0-7 or SUN-SAT 1-5
Command The command to run /home/user/scripts/daily-report.sh

In the example output:

  1. A daily report runs at 9:00 AM on weekdays
  2. An evening backup runs at 6:30 PM every day
  3. A monthly cleanup runs at midnight on the first day of each month

Handling Cases with No Cron Jobs

If no cron jobs are set for the current user, you'll see this message:

no crontab for [username]

Viewing User Cron Job Directory

User crontab files are typically stored in the /var/spool/cron/crontabs/ directory. However, direct access to this directory is often restricted for security reasons.

Common Locations of User Crontab Files

  • /var/spool/cron/crontabs/
  • /var/spool/cron/
  • /var/cron/tabs/

Accessing User Crontab Files

To view the contents of your crontab file directly:

sudo cat /var/spool/cron/crontabs/$USER

Note: This method requires root privileges and should be used carefully.

Cron Job Format Explanation

graph TD A[Cron Job Format] --> B[Minute 0-59] A --> C[Hour 0-23] A --> D[Day of Month 1-31] A --> E[Month 1-12 or JAN-DEC] A --> F[Day of Week 0-7 or SUN-SAT] A --> G[Command to Execute]

Special characters:

  • *: Any value
  • ,: Value list separator
  • -: Range of values
  • /: Step values