LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Is it OK to delete everything in /tmp? (http://www.linuxquestions.org/questions/slackware-14/is-it-ok-to-delete-everything-in-tmp-382955/)

forrest44 11-14-2005 05:10 AM

Is it OK to delete everything in /tmp?
 
well I've got slackware 10.0 on my computer..

I'm pretty tight for disk space, and I noticed that the /tmp directory had about 120mb of stuff in it.

Is it ok to delete EVERYTHING in the /tmp directory or is there some stuff I need to leave behind?

Cheers
Forrest

LiNuCe 11-14-2005 05:19 AM

Re: Is it OK to delete everything in /tmp?
 
Yes, you can remove everything in /tmp. A (the?) proper way to do this is to login as root, then to switch to single user mode with the init 1 command and to use the following commands to create a sane /tmp hierarchy :

Code:

# rm -rf /tmp
# mkdir -m 1777 /tmp
# mkdir -m 1777 /tmp/.ICE-unix
# mkdir -m 1777 /tmp/.X11-unix

You can then reboot if you wish or you can switch back to multi-user mode with the init 4 command.

--
LiNuCe

rkelsen 11-14-2005 05:29 AM

Personally, I avoid the issue altogether and run a 'tmpfs', i.e: a ramdisk which is mounted under /tmp at bootup. Don't have to worry about deleting stuff this way - it goes away when I shutdown the computer.

Refer to /path/to/kernel/source/Documentation/filesystems/tmpfs.txt for more info.

LiNuCe 11-14-2005 06:02 AM

Quote:

rkelsen: Refer to /path/to/kernel/source/Documentation/filesystems/tmpfs.txt for more info.
Another interesting reading before switching to tmpfs is this article published by IBM.

--
LiNuCe

rkelsen 11-14-2005 06:37 AM

Quote:

Originally posted by LiNuCe
Another interesting reading before switching to tmpfs is this article published by IBM
The change to 'tmpfs' will only be permanent if you want it to be. Try it. If it degrades your system performance, switch back. Simple.

In ~ 4 years (or however long its been since tmpfs came out) I've not experienced the problems discussed in the IBM article. But then I like to load my mobos with all the RAM they can carry.

jong357 11-14-2005 09:32 AM

That's not a bad idea with tmpfs... I just append to the startup script. When it cleans /var/lock, I have it wipe /tmp as well. Those required sockets seem to get created automatically.

forrest44 11-14-2005 02:53 PM

Well thanks for all the help..

I'm guessing it would be OK to add something like "rm -rf /tmp" to the shutdown script?

forrest44 11-14-2005 02:54 PM

Oh and I don't think I'll use the tmpfs thing, I've only got 128mb ram

Woodsman 11-14-2005 06:16 PM

I run KDE. In my rc.local, I run two scripts:

#!/bin/bash
# /usr/local/sbin/deleteoldfiles
# delete old tmp files

echo "Deleting old tmp files."
TMPDIRS="/tmp /var/tmp" # list of directories to clean
for d in $TMPDIRS; do
find $d ! -type d -mtime +10 -exec rm -f {} \;
find $d -type d -mtime +10 -exec rmdir {} \;
done

#!/bin/bash
# /usr/local/sbin/cleanup
# delete various tmp files

echo "Deleting various tmp files."
# first delete known single files
rm -f /tmp/.ICE-unix/* /tmp/kio*
# next delete files recursively
rm -rf /tmp/kde-root/* /tmp/kde-username/* /tmp/kde-tester/* /tmp/.wine*

# Delete login manager logs for easier session troubleshooting and maintenance
rm -f /var/log/kdm.log >/dev/null
rm -f /var/log/xdm.log >/dev/null
# rm -f /var/log/gdm.log >/dev/null


The ideas for the scripts are not original. I saw what some other people have done and simply adopted the ideas. I hope this helps.

LiNuCe 11-14-2005 06:54 PM

Quote:

forrest44: I'm guessing it would be OK to add something like "rm -rf /tmp" to the shutdown script?
I think it should be safe to replace the following line :
Code:

echo "Unmounting local file systems."
with the following ones in the /etc/rc.d/rc.6 shutdown script :
Code:

rm -rf /tmp
mkdir -m 1777 /tmp
echo "Unmounting local file systems."

--
LiNuCe

alienDog 11-15-2005 04:15 PM

Or you could have a cron script for cleaning up /tmp, something like:

Code:

#!/bin/bash
find /tmp -type f -atime +3 -exec rm {} \;

The above would find all regular files not accessed in three days and remove them. It's better than shutdown/startup script solution since it will also work if you keep your box powered up.

jong357 11-15-2005 09:50 PM

I like that even better... I've gotten in the habit of never using /tmp to store stuff, but you never know. You could build a new mozilla package and then forget to remove it before a reboot. Then you'd have to spend another hour building the package...

Nice suggestion aliendog.

LiNuCe 11-15-2005 11:47 PM

Quote:

jong357: I like that even better... I've gotten in the habit of never using /tmp to store stuff, but you never know. You could build a new mozilla package and then forget to remove it before a reboot. Then you'd have to spend another hour building the package...
The traditional pratice is to assume that temporary files in /tmp/ are removed between system reboots, whereas temporary files in /var/tmp/ are not . So, if you want to keep temporary files between reboots, you would probably store them in /var/tmp/. By default, Slackware Linux does not remove temporary files in /tmp/ between reboots, however many Unix/Linux systems remove them (or store them in a temporary filesystem such as tmpfs). Note that you can ignore this traditional pratice on your system until Slackware Linux uses tmpfs for /tmp/ by default, but this is something to know to avoid problems on others systems.

--
LiNuCe


All times are GMT -5. The time now is 01:01 AM.