Need Help Cleaning Temp & Var/Temp Files

I was attempting to do something a bit outside the realm of normal a few days ago: grabbed Hugin photo stitcher from the repos and attempted to output a massive file from 3 24.6 MPix photos. While things were chugging along Hugin was writing a massive temp file and I got an error about running out of root space. I looked up the issue, but things listed seem to be depreciated. The threads I read said to manage temp files via /etc/sysconfig/cron, but when I open the file I see that there is now supposed to be a separate temp config file in etc/tmpfiles.d, which conveniently is not there. Can I still use the depreciated values in cron without an issue? Is it safe to simply rm -rf the tmp folder?


To remove things from /tmp while the system is running is a bit tricky. You never know which process is thinking it still has some file there and thus will get into trouble.

Cleaning on boot in these days where we use systemd is best done by configuring /etc/tmpfiles.d/tmp.conf. When this does not exist (which is normal when you never created one already, the file in /etc will overrule the file in /usr/lib), create it using

cp /usr/lib/tmpfiles.d/tmp.conf /etc/tmpfiles.d/tmp.conf

Look for the /tmp and /var/tmp lines. I changed them to

D /tmp 1777 root root 1d
D /var/tmp 1777 root root 1d

Probably not a good idea to delete temporary files that belong to the current session. Assuming that you have logged out and/or rebooted in the last 48 hours, the traditionalŧ¹ method would be to delete all files not modified in the last two days with:

#  find /tmp  -mtime +1 -delete
#  find /var/tmp  -mtime +1 -delete 

¹ I am, regrettably, old enough to remember such tasks as part of routine system administration.


#  find /tmp  -size+1M -delete
#  find /var/tmp  -size +1M -delete 

would remove files larger than 1MiB, which should exclude any important lock or configuration files.

Awesome, thanks. I was dreading having to find out how to create this file on my own tmp.conf file (not much time lately). Copy and paste from the system itself is always good, but why not just have is available in the correct place in the first place? I’m also assuming 1d is removing files more than a day old (correct)?


My preferred method of hard cleaning those directories is to (once a week or so) cold boot into a root console, cd to the directories, then:

rm -R *

adding a few extra file wildcards to that command (ie: .X*).

Do an

ls -l

first to see what is there and how to add it to your command, such as the .X* case.

I like that much better, just the feeling of power it gives >:) , and the clean response to ls -l afterwards.

Just make certain you are in the correct directory, and be aware that everything in that directory and all the way down the contained paths will be zapped. The -R option is for recursive deletions. If you send it from the wrong directory, you will smack your forehead and be sent scrambling for your backups.

You do have good, up-to-date backups, don’t you?lol!

I am not sure I understand you complete, but thye way systemd works here is having a default configuration file in /usr/lib. The system administrator should of course not change that because it will be overwritten with the original when re-installed/updated.

The file in /etc will nullify the one in /usr/lib. (other product may act different, a sceme might be: first use lines in /usr/lib, then add lines, that may be an addition or an overrul of the earlier lines, found in /etc, and even then act on lines find in a user’s home directory)

And like the 1d, it is of course all in the man page:

man tmpfiles.d