How to install and use tmpreaper

The files and directories in the tmp directory are cleaned only during a reboot. This can be problematic if you have applications that write a lot to the tmp directory and you do not want to reboot your Linux system. A good solution for periodic cleanup of the tmp directory is the tmpreaper tool.

  • Installing it is easy:
$ sudo apt install tmpreaper
  • On installation, tmpreader adds a cron job that runs once a day. This can be seen in /etc/cron.daily/tmpreaper. It calls the tmpreaper program with the options you set in /etc/tmpreaper.conf

  • The tmpreaper tool will work on any directory passed to it, including the root directory. Since deleting the root directory is catastrophic, tmpreaper shows a warning all the time. You can disable this warning by setting SHOWWARNING=false in /etc/tmpreaper.conf

  • When tmpreaper is run once a day by cron, it uses the TMPTIME value set for the tmp directory init scripts as described here to decide which files and directories to delete. For example, if TMPTIME=1, then tmpreaper will delete everything in tmp directory that is older than a day.

  • If you want to apply tmpreaper on directories other than /tmp, then add them to the TMPREAPER_DIRS value in /etc/tmpreaper.conf

  • You can call the tmpreaper program directly at the shell to reap your own directories. For example, to reap all files and directories older than 2 days from the tmp directory:

$ tmpreaper 2d /tmp

Note that you might need to run that command as sudo to be able to delete files created by other users.

  • To be sure that you are not deleting important file, make sure you use the --test option to do a dry run:
$ tmpreaper --test 2d /tmp

Tried with: tmpreaper 1.6.13 and Ubuntu 16.04

One thought on “How to install and use tmpreaper

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.