Linux Commands

How To View All Jobs in Crontab?

Servers can be set to perform tasks or run scripts automatically. In Linux, you can use the cron utility to configure the task or scripts your server should run at a specified time. Any cron jobs on your server are located in the spool directories in the /var/spool/cron/crontabs. The crontab lists all cron jobs for users, excluding the root user. However, if you need to view the cron jobs of the entire system, you must be a root user.

This article covers how you can list all jobs in crontab for the system, current users, and other users. Sounds good? Let’s get started.

How To List cron Jobs

The crontab lists jobs based on a user, and with an administrator privilege, you may view jobs of another user.

1. Viewing Cron Jobs for Current User

When creating a cron job, specify which user the scheduled job falls under. If no user is specified, the crontab file schedules the job for the currently logged user. In that case, you can use the following command to list the scheduled jobs for the current user:

$ crontab -l

In the following output, you can note the scheduled jobs listed at the bottom of the file:

2. Viewing All Cron Jobs of Another User

To view the jobs of another user, you use the -u flag followed by their username. Also, you will need administrator privilege for this to work. For instance, the following command views the cron jobs of a user named linuxhint1.

$ sudo crontab -l -u linuxhint1

Your target user’s jobs will be displayed in a crontab file like the one shown below:

3. Viewing All cron Jobs as Root

The crontab in the spool directory doesn’t list the jobs for the root user. To view the crontab containing the various jobs for the whole system, open the /etc/crontab file.

$ less /etc/crontab

The previous output lists all the cron jobs for the entire system. Note that there are four categories of system jobs. The hourly, daily, weekly, and monthly jobs. If you want to edit the system crontab, you can open it using an editor like nano. The command for that would be as shown below. Note that you must be a root user to access the crontab file.

# nano /etc/crontab

To view all the hourly cron jobs, run the following command:

# ls -la /etc/cron.hourly

In the previous output, we have no hourly cron job. By default, you should get a result similar to the one above with two directories and the .placeholder, which helps avoid the accidental deleting of directories on your system by the package manager.

To view the daily cron jobs, use the following command:

# ls -la /etc/cron.daily

You can note the daily jobs for various system processes in the previous output.

Similarly, the following command lists all the weekly cron jobs.

# ls -la /etc/cron.weekly

Lastly, you can view the system’s monthly cron jobs using the following command:

# ls -la /etc/cron.monthly

We only have one monthly cron job, as shown above.

4. Viewing Cron Jobs for Specific Applications

It’s possible to list the cron jobs for the various applications running on your system. Here, you can choose the category to view the specific application. For instance, the following command views the daily cron job for Google Chrome:

# cat /etc/cron.daily/google-chrome

Conclusion

Working with cron to automate scripts and jobs for your Linux system or server is amazing. We’ve covered the various ways you can list all the crontab jobs, including for the current user, another user, and working with root to get system cron jobs. Further, we discussed how you could list the hourly, daily, weekly, and monthly jobs. Try it out and see your cron jobs.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.