Purging computer temp folder

A Linux computer temp folder can be purged on schedule to free up disk space and remove old temporary files. The programs “tmpwatch” or “tmpreaper” can be used to purge the temp folder on a schedule. tmpwatch is available on Red Hat-based Linux distributions, while tmpreaper is available on Debian-based Linux distributions.

To do a “dry run” of the purge command to see what files would be deleted, use the “–test” flag:

<tmpwatch|tmpreaper> --test --mtime 7d /tmp

Set the temp path explicitly, especially on HPC systems where scratch space may be under system-specific paths.

--mtime 7d
purge files older than 7 days – adjust as desired
/tmp
path to the temp folder – adjust as needed

Linux cron example

On Linux, a cron job can run the purge command on schedule.

Edit the crontab with:

crontab -e

Add a line to run the purge command daily at midnight:

0 0 * * * /usr/bin/tmpwatch --mtime 7d /tmp