View Full Version : clean up TMP files (linux not so good at it)

7th March 2013, 10:20 PM
Fedora 18 now cleans /tmp but has substituted /var/tmp for system work which does not get cleaned ever as far as I can see.

The following one-liner can be put in a root crontab (suggested to run weekly - say Sunday 2am) and/or put in /etc/rc.d/rc.local - whichever suits you (if you boot often, the latter is enough, if you never boot then you need a crontab entry). It removes files and directories over one day old.

/bin/find /tmp /var/tmp -mtime +1 -exec /bin/rm -rf {} \;

Personally as I boot often, it is part of rc - and works VERY well. I use crontab entries for servers that "never" reboot.

Itt is best to use full path names for things root does SO please don't shorten the executable names.

7th March 2013, 10:42 PM

man tmpfiles.d

8th March 2013, 02:14 PM
NICE - sorry I missed

9th March 2013, 04:27 PM
/var/tmp does get cleaned up. I believe it defaults to leaving files for 30 days since last access, though.

If you wish to change that to something different, copy /usr/lib/tmpfiles.d/tmp.conf to /etc/tmpfiles.d/tmp.conf and edit the line for /var/tmp

9th March 2013, 10:54 PM
thanks - I boot often so I guess the profusion of files had not reached 30 days before I started to clean.

10th March 2013, 02:28 AM
I believe the systemd service to clean up the tmp files runs about 10-15 minutes or so after boot, and then on a schedule after that. Not sure exactly how often it runs, though, I would have to look to find out.

But, yes, if you clean it out manually before the 30 days, then you probably would never see where it cleans it for you. (I do the same thing.. I like to keep mine cleaned out as well)

10th March 2013, 01:39 PM
Given that my home system is rebooted quite often a lot of files are built by the OS at boot, so I am with you here.

My script works nicely at boot time.

But using the tmp.d files is neat too so I will investigate a combination.

And for the record - the clutter is a combinationi of "systemd-private-..." and system download files (sometimes they go in /var/tmp and sometimes in ~/Downloads - who knows why the former when the latter is what I set)