How to completely erase /tmp

From Salix OS
Revision as of 22:31, 30 November 2010 by Witek (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Although Salix does provide /tmp cleanup during boot in /etc/rc.d/rc.S:

# Clean up some temporary files:
rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
 /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
 /var/state/saslauthd/saslauthd.pid \
 /tmp/.Xauth* 1> /dev/null 2> /dev/null
 ( cd /var/log/setup/tmp && rm -rf * )
 ( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )

one might need to completely erase the contents of /tmp directory for some reason. There might be several ways to to so, either by modifying the above script or by scheduling the cleanup via crontab. The easiest way however is adding some simple lines to the above script:

echo "cleaning up /tmp completely"
rm -rf /tmp/*
rm -rf /tmp/.??*

The first rm command deletes all non-hidden directories and files, the second removes most of the hidden ones. CAUTION: a typo in the last command (only one question mark) might lead to removal of all files in the system: rm -rf /tmp/.?* as this matches /tmp/../ which is equivalent to root directory /. Two question marks prevent this and match only files inside /tmp directory.

We might also want to wipe /var/tmp - similarly add these lines:

rm -rf /var/tmp/*
rm -rf /var/tmp/.??*