Cron is a scheduling daemon, used to schedule the execution of any tasks at specified time intervals. Such tasks (cron jobs) can be schedule to run at every minute, 5 minute, hour, day of the month, day of week, etc. Generally, cron jobs are used to perform repeated tasks, such as to backup databases, clearing cache, sending emails, and more. In guide explains how to list the cron jobs.
Listing Users Cron Jobs
The crontab files are stored on different location on different Linux distributions. Red Hat based distributions like CentOS, crontab files are stored at the /var/spool/cron
directory, where on Debian based distributions files are stored in the /var/spool/cron/crontabs
directory.
Run the following crontab command to get the list of all cron jobs for the currently logged in user:
crontab -l
The output show message that no crontab for USERNAME
if the user has not set up any cron jobs, otherwise it will list the cron jobs.
You also can get list of the other users cron jobs by using the -u
option followed by the username. For example, to list the cron jobs of the user named “kunj” you would use:
sudo crontab -u kunj -l
Each crontab file is owned by the perticular user and having the 600 permissions. Make sure you should logged in as root or sudo privileged user to view the cron jobs of other users.
To find out which users have created cron jobs, list the content of the spool
directory as root or sudo user:
sudo ls -1 /var/spool/cron/crontabs
It will show output like below:
root tecnstuff
Listing System’s Cron Jobs
You can find the system cron jobs in /etc/crontab
and the files inside the /etc/cron.d
directory. Only the system administrators can be edit these crontab files.
You can view the content of crontab file using cat, less or any text editor:
cat /etc/crontab /etc/cron.d/*
In most Linux distributions you can also put scripts inside the /etc/cron. {hourly,daily,weekly,monthly}
directories, and the scripts are executed every hour/day/week/month
.
Make sure that all the files inside these directories must have execute permission, otherwise it will execute.
For example, to view all daily cron jobs, you would type:
ls -l /etc/cron.daily/
-rwxr-xr-x 1 root root 376 Nov 20 2017 apport
-rwxr-xr-x 1 root root 1478 Apr 20 2018 apt-compat
-rwxr-xr-x 1 root root 355 Dec 29 2017 bsdmainutils
If there is no any jobs then output will be empty.
Systemd Timers
Systemd timers are unit files, allow you to run service units based on time. These files are end with *.timer
extension.
To get list of all systemd timers on your machine run the following command:
systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVASun
2020-10-04 07:09:00 UTC 41s left Sun 2020-10-04 06:39:08 UTC 29min ago phpsessionclean.timer phpsesSun
2020-10-04 08:43:55 UTC 1h 35min left Sat 2020-10-03 16:46:12 UTC 14h ago motd-news.timer motd-nSun
2020-10-04 10:46:28 UTC 3h 38min left Sat 2020-10-03 20:37:04 UTC 10h ago certbot.timer certboSun
2020-10-04 12:32:47 UTC 5h 24min left Sun 2020-10-04 02:39:46 UTC 4h 28min ago apt-daily.timer apt-daSun
2020-10-04 14:23:02 UTC 7h left Sat 2020-10-03 14:23:linu02 UTC 16h ago systemd-tmpfiles-clean.timer systemMon
2020-10-05 00:00:00 UTC 16h left Mon 2020-09-28 00:00:01 UTC 6 days ago fstrim.timer fstrimMon
2020-10-05 06:47:16 UTC 23h left Sun 2020-10-04 06:07:18 UTC 1h 1min ago apt-daily-upgrade.timer apt-da
Conclusion
This article shows you how to list the cron jobs and systemd timers on Linux system.
If you have any questions or feedback, feel free to leave a comment below.