How to View and List Cron Jobs Using Crontab
The cron utility on Unix-like operating systems allows users to schedule tasks (commands or scripts) to run automatically at specific times or intervals. Whether you are maintaining a server or managing automated tasks on a local machine, cron is an essential tool for system administrators and developers.
This article explains how to view and list cron jobs using the
crontabWhat Is the Crontab Command?
Crontab (short for “cron table”) is a file that defines scheduled tasks for the cron daemon. Each user on a system, including the
rootA crontab entry follows this syntax:
* * * * * command_to_be_executed
| | | | |
| | | | +----- day of the week (0–7) (Sunday = 0 or 7)
| | | +---------- month (1–12)
| | +--------------- day of the month (1–31)
| +-------------------- hour (0–23)
+------------------------- minute (0–59)
This structure allows precise control over when tasks are executed, making cron a powerful automation tool.
How to List Cron Jobs Using Crontab
The
crontab1. View Your Own Cron Jobs
To display cron jobs for the currently logged-in user, run:
crontab -lThis command lists all scheduled cron jobs for the current user. If no cron jobs exist, it may return an empty output or a message indicating that no crontab is defined.
Example output:
# m h dom mon dow command
0 0 * * * /home/user/backup.sh
30 2 * * 7 /home/user/scripts/cleanup.sh
In this example:
- A backup script runs daily at midnight.
- A cleanup script runs every Sunday at 2:30 AM.
2. List Cron Jobs for Another User
If you have
sudo-usudo crontab -l -u usernameReplace
usernamesudo crontab -l -u johnThis displays all cron jobs scheduled for the specified user.
3. List System-Wide Cron Jobs
In addition to user-specific cron jobs, there are system-wide cron tasks scheduled by the system or the root user. These are typically stored in:
/etc/crontab/etc/cron.d//var/spool/cron/crontabs/
To view the main system crontab file, run:
cat /etc/crontabExample output:
SHELL=/bin/sh
PATH=/usr/bin:/usr/sbin
# 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 )
This configuration schedules hourly, daily, weekly, and monthly system maintenance tasks.
To list additional system cron files, run:
ls /etc/cron.d/Each file in this directory may define additional scheduled tasks for system services.
4. View Cron Jobs in /var/spool/cron
User-specific crontab files are usually stored in
/var/spool/cron/crontabsls /var/spool/cron/crontabsTo view the contents of a specific user’s crontab file:
cat /var/spool/cron/crontabs/usernameThis provides the same output as
crontab -l -u usernameEditing Cron Jobs
To edit or add cron jobs for the current user, run:
crontab -eThis opens the crontab file in the default text editor. After saving and exiting, the changes take effect immediately.
Example: run a script every day at 3:00 AM:
0 3 * * * /home/user/script.shCommon Crontab Listing Commands
- List current user’s cron jobs:
crontab -l - List another user’s cron jobs (sudo required):
sudo crontab -l -u username - View system crontab:
cat /etc/crontab - List cron files in /etc/cron.d/:
ls /etc/cron.d/ - List user crontabs:
ls /var/spool/cron/crontabs
Conclusion
Viewing and listing cron jobs using
crontabBy mastering cron, you can automate repetitive tasks, manage backups, and maintain consistent execution of scripts across your environment.
