Cron jobs allow you to schedule tasks and processes in Linux. Sometimes you may need to list all cron jobs for all users. In this article, we will look at how to display cron jobs for all users as well as specific users.
How to List All Cron Jobs for All Users
There are various ways to view cronjobs in a system.
1. Using system crontab
You will find a list of all cron jobs that are applicable system-wide in /etc/crontab file. Only privileged users can write to this file. Open terminal and run the following command to display all cron jobs.
$ sudo cat /etc/crontab 0 0 * * * ubuntu service.py
In the above output, the first 5 characters indicate the schedule of cron job. It is followed by the username (e.g. ubuntu) and finally the actual command to be run (e.g. service.py).
Please note, crontab is separate for each user. So you cannot see other user’s cron jobs unless you are root or logged in as the other user.
Here is a simple command to organize the above output neatly for each user. This is useful if you have too many users/cronobs in your system.
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
2. Using cron.d
You may also view /etc/cron.d folder for cron jobs of all users.
$ sudo cat /etc/cron.d
Again this file is also separate for each user and you need to have root/sudo privileges to be able to view information about all users.
3. View user-specific crontab
/var/spool/cron/crontabs contains separate crontab files for each user. You can view them to take a look at the cronjobs for each user. Here are the commands to view user-specific cronjobs.
$ cat /var/spool/cron/crontabs/*
$ cat /var/spool/cron/*
That’s it. As you can see cronjobs are scattered across /etc/crontab, /etc/cron.d as well as /var/spool/cron/crontabs folders and may require multiple commands to get a complete list of all cronjobs for all users. Also, you will need root privileges to be able to view cronjobs of other users. Otherwise, you will only be able to see your own cronjobs.
Also read :