clearing out /tmp safely

Tom Mitchell mitch48 at sbcglobal.net
Wed Jan 21 10:00:15 UTC 2004


On Wed, Jan 21, 2004 at 10:44:14AM +1000, Matt H. wrote:
> 
> I would like to clean out my /tmp partition as per the tip at 
> http://fedoranews.org/krishnan/tips/tip014.shtml. However, just one small

Yes this is a bit heavy handed.  

You may not need to bother.  On Fedora there is a cron task that
cleans up /tmp and /var/tmp

 /etc/cron.daily/tmpwatch

It has two lines of interest here:

   /usr/sbin/tmpwatch 240 /tmp
   /usr/sbin/tmpwatch 720 /var/tmp

If you are out of space you can look for trouble files or just
run these by hand with 'short' times. Something like.

	/usr/sbin/tmpwatch 120 /tmp  # five days
    or
	/usr/sbin/tmpwatch 24  /tmp  # one day

Check out the man page for tmpwatch:
   tmpwatch - removes files which haven’t been accessed for a period of time

Also if you are out of space today when yesterday was fine look
for the new file or interesting directory that is big and
trouble.  Remove only that one file or dir, I start looking with:

	ls -ltr /tmp /var/tmp | tail -20

On some SysV based operating systems /tmp is flushed at reboot.
This is not true for RH Linux.

I am not sure I like this idea but, it would be simple to add a
'once' line to inittab to prune the /tmp dir more aggressively and
get a more SysV like behavior.  Perhaps:

	/usr/sbin/tmpwatch 1  /tmp  # one hour

Just remember that you cannot remove a file and get back disk
space that a runaway program has open. This is why I like to do
the "ls -ltr" thing and then as you did use "lsof" to find out
more.   If this is a shared machine see also limits and quotas.


-- 
	T o m  M i t c h e l l 
	mitch48-at-sbcglobal-dot-net





More information about the fedora-list mailing list