LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Is it safe to delete the contents of /tmp? (http://www.linuxquestions.org/questions/slackware-14/is-it-safe-to-delete-the-contents-of-tmp-519134/)

tramni1980 01-14-2007 05:22 AM

Is it safe to delete the contents of /tmp?
 
Hello!
I am running Slackware Linux 11.0
I want to ask if it is safe to delete entirely the contents of the /tmp directory, in order to free space? Is there something necessary for the system there?
I would also like to know if there are some other directories where one can safely delete everything from time to time, without any risk.

Thank you for your attention.
Regards,
Martin

druuna 01-14-2007 05:46 AM

Hi,

/tmp is needed by programs to store (temporary) information.

It's not a good idea to delete files in /tmp while the system is running, unless you know exactly which files are in use and which are not.

/tmp can (should) be cleaned during a reboot. Some distro's do this by default, others don't.

You could check the log directories and remove old logfiles (maybe set up logrotate to automate rotation and removal of old files).

To check for large files you can do the following (as root):

cd /
du -sh *


This will give you a list with dirs and their size. From here you can zoom in on the biggest dir(s) and repeat the du -sh process.

Hope this helps.

The Headacher 01-14-2007 05:52 AM

Well, no permanent harm should be done if you remove /tmp. As a matter of fact, my distro has /tmp in RAM, to speed up things a little. So, every time you boot you'll have a clean /tmp. Make sure you save important work you might be doing before cleaning up /tmp/ though, just to be sure.

tramni1980 01-14-2007 06:49 AM

Quote:

Originally Posted by druuna
/tmp can (should) be cleaned during a reboot. Some distro's do this by default, others don't.

It seems that Slackware does not clean /tmp on reboot. To which script and where in the script should I add something like:
sudo rm -rf /tmp/*
so that at reboot my system is with a brand new /tmp?
I think it should be added to /etc/rc.d/rc.6, but I am not sure where I should place the above line of code.

Randux 01-14-2007 07:00 AM

Quote:

Originally Posted by tramni1980
Hello!
I am running Slackware Linux 11.0
I want to ask if it is safe to delete entirely the contents of the /tmp directory, in order to free space? Is there something necessary for the system there?
I would also like to know if there are some other directories where one can safely delete everything from time to time, without any risk.

Thank you for your attention.
Regards,
Martin

Yes it is safe as long as you are either shutting down or coming up and nobody is using it.

There were a few posts on the topic of what to do about this and many guys said that they write simple shutdown scripts to delete everything in /tmp. Otherwise it will fill with junk over time.

You can write a script to run at shutdown and do this:

rm -rf /tmp/* 2> /dev/null
rm -rf /tmp/.* 2> /dev/null

Rand

Randux 01-14-2007 07:01 AM

I posted before seeing your update. You can add it right before "turning off swap and unmounting..."

tramni1980 01-14-2007 08:11 AM

Thank you very much for your responsiveness.
:)
Regards,
Martin

H_TeXMeX_H 01-14-2007 02:05 PM

I've found it to not be quite as safe ... unless you do it at shutdown. If you really have to, do it at shutdown.

Prostetnic_Jeltz 01-14-2007 02:35 PM

here's a great utility to help you free up space on disk:

http://xdiskusage.sourceforge.net/

slzckboy 01-14-2007 02:48 PM

http://www.linuxquestions.org/questi...d.php?t=505984

jong357 01-14-2007 03:28 PM

Theres no right or wrong way, but I think its more proper from within rc.S. Why make another section somewhere else when Pat is already doing the same thing in rc.S?

snip of my rc.S
Code:

# Clean up some temporary files:
( cd /var/log/setup/tmp && rm -rf * )
/bin/rm -f /var/run/utmp /var/run/*pid /etc/nologin /var/run/lpd* \
  /var/run/ppp* /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
  /var/state/saslauthd/saslauthd.pid /root/.serverauth.* /root/.recently-used
echo "Cleaning /tmp"
mkdir /saved-packages
mv /tmp/*.tgz /saved-packages > /dev/null 2>&1
rm -rf /tmp/*
mv /saved-packages/* /tmp > /dev/null 2>&1
rm -rf /saved-packages

# Create /tmp/{.ICE-unix,.X11-unix} if they are not present:
if [ ! -e /tmp/.ICE-unix ]; then
  mkdir -p /tmp/.ICE-unix
  chmod 1777 /tmp/.ICE-unix
fi
if [ ! -e /tmp/.X11-unix ]; then
  mkdir -p /tmp/.X11-unix
  chmod 1777 /tmp/.X11-unix
fi

I build packages all the time and there is NOTHING MORE FRUSTRATING than rebooting but yet forgetting to snag my packages first...

pbhj 01-14-2007 08:12 PM

don't delete /tmp without a backup!
 
I recall, vaguely, doing this - deleting entire content of /tmp - and finding that KDE wouldn't start after next boot. YMMV.

I now have in /etc/rc.d/rc.local_shutdown (which is surely the place for local variations on shutdown scripts ... not rc.S!).

Code:

# Clear /tmp directory of older files (>10 days since accessed)
find /tmp -type f -atime +10 -exec rm {} \;
echo rc.6: deleting /tmp files not accessed in 10 days;


jong357 01-14-2007 10:38 PM

Well, who says /tmp should be cleared on shutdown? Most distro's I'm aware of do it on startup. Since Slackware allready cleans tmp cruft up in rc.S, that would make it a prime canidate for such modifications.

I do like removal by time tho. In some cases that wouldn't help me because I can accumulate gigabytes worth of stuff in just a few hours. It all depends on how much hard drive space you have I suppose.

gnashley 01-15-2007 07:52 AM

I find either way to work and think it's a matter of choice. Pat probably doesn't do it by default because it might delete something you want or need. Doing it in rc.S where the other stale files are cleaned up makes perfect sense to me -though it may add considerable time to the bootup. Doing it in rc.local_shutdown is probably better from a data-security standpoint.
I don't doubt that there are programs which may complain, but with the desktop I run I can usually delete the whole contents, even on-the-fly, without any problems.

TSquaredF 01-15-2007 09:23 AM

I have been using rc.6 to:
Quote:

rm -rf /tmp/* /var/tmp/*
I have been warned by various posts that deleting /var/tmp is dangerous, but I have never had any problems.

jong357:
I've had hassles with my scripts as well, so I defined an variable, OUTPUT, per shilo's recent slackbuild post, & set a safe destination for them.
Regards,
Bill


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