LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2005, 09:26 AM   #1
ginda
Member
 
Registered: Mar 2004
Distribution: SUSE8.2, 9.2, Knoppix
Posts: 323

Rep: Reputation: 31
TMP folder, is everything deletable in there?


I was just wondering the /tmp folder is everything just temp file sin there?what is it used for?
 
Old 03-07-2005, 09:42 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Not everything in there is deletable, it would do bad things. /tmp is used as a "storage" area for currently running programs. I use it for when I want to just store something in and don't care if I forget about it or not ( even though I'm usually good in my clean up ). Things that are placed in /tmp will be removed when the machine is rebooted.

Typically, you don't want to just start deleting things that are in there on a whim...but who knows, maybe you can, give it a try, that's the only way you'll know for sure! :-D
 
Old 03-07-2005, 09:55 AM   #3
jxi
Member
 
Registered: Feb 2003
Location: Richmond VA
Distribution: Slackware 11 -- CentOS 4.4
Posts: 115

Rep: Reputation: 15
First of all, don't attempt to delete everything in /tmp if you have gui sessions and/or a number of services running...
but, (if you are asking whether it is safe to delete everything in /tmp before a shutdown or reboot), the answer is yes, though you would typically perform the delete with a privelged account /process.

While one or more gui sessions are running there are lock files in /tmp that are necessary to keep things in order. also, If your're running something like mysql it may maintain a socket in /tmp for communication client to server.

if your box is running all the time and you are concerned about /tmp getting cluttered you could run (as root)

LASTCHNG='+2' # set to the number of days back files are considered 'old'
find /tmp/* -ctime $LASTCHNG -exec rm -rfv {} \;

20061216 edited the above line, taking out `#' at the beginning (it was supposed to represent the root prompt :/

Regards,
JOhn I.

Last edited by jxi; 12-16-2006 at 11:43 AM.
 
Old 12-15-2006, 10:01 AM   #4
syinx
LQ Newbie
 
Registered: Oct 2006
Location: India
Distribution: Suse
Posts: 4

Rep: Reputation: 0
Question "Another query on /tmp"

I am using suse 10.0 , It has created many temporary files in /tmp folder around 3 GB , How do I know which files i could delete while i am running. or can i delete all while running in safe mode.

any suggestions please.
 
Old 12-16-2006, 12:09 PM   #5
jxi
Member
 
Registered: Feb 2003
Location: Richmond VA
Distribution: Slackware 11 -- CentOS 4.4
Posts: 115

Rep: Reputation: 15
Did you try the above code I posted?

Since then I added checking for open files. The following bash script seems to work :
Code:
#!/bin/bash
TMPMSG='/root/Tmpclean.msg'
cat /dev/null >$TMPMSG
for I in /tmp /var/tmp
do
    tmpLSOF=`mktemp /tmp/SnapLSOF.XXXXXXX`
#safety kludge
    if [ -z $tmpLSOF ]
    then
        tmpLSOF='/tmp/heyINeedToInstallmktemp'
    fi  
#end safety kludge  
    lsof > $tmpLSOF
    find $I ! -type d -a -cmin +500 -print 2>>$TMPMSG | while read J
    do 
        echo "processing found item $J"
#Check for open files before deleting from tmp
        if [ 0 -eq $(cat $tmpLSOF |grep "$J" 2>/dev/null | wc -l) ]
        then 
            echo "File $J can be deleted"
            rm -v "$J"
        else 
            echo '*------------------------------------*'
            echo "File CANNOT be deleted: $J"
            lsof |grep "$J"
            echo '*------------------------------------*'
        fi
    done
    echo "$0 running empty directory check in $I ..."
    find $I/* -depth -type d -empty -exec rmdir {} \; 2>>$TMPMSG
done
This is run from root's cron entry specifying every 8 hours. Tweak the frequency (along with `-cmin +500' on line 8) to your style.

Caveats:
o You must have mktemp installed to run without the kludge for the output file of `lsof'

o On some systems /var/tmp is a symlink to /tmp so a separate loop for it would be a waste.

o The echo statements are just for a sanity check. They can be safely deleted (in face the entire else stanza inside the `do' can be).

o Some might question putting the output of `lsof` into a file on /tmp, where stuff is being deleted. -cmin + <minutes> protects you.

o the `rm' on line 21 could also need the -f (force) flag.

Last edited by jxi; 12-16-2006 at 12:29 PM.
 
Old 12-16-2006, 12:46 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Weird nobody mentioned tmpwatch yet.
 
Old 12-16-2006, 01:43 PM   #7
jxi
Member
 
Registered: Feb 2003
Location: Richmond VA
Distribution: Slackware 11 -- CentOS 4.4
Posts: 115

Rep: Reputation: 15
Good Point

unSpawn: yes, tmpwatch would be the smarter way to go, if it's installed. When I got fedora going again recently I saw it in /etc/cron.daily but went ahead and copied my script from the slack box. `tmpwatch' didn't seem to be doing anything. Now looking at it, i see why, the default settings are very conservative. 10 days since file accessed, 30 days for /var/tmp.

tmpwatch is no doubt safer (checks for possible race conditions). guess i'll adjust the settings and re-enable it on fedora.

syinx: if tmpwatch is not installed it should be available thru yast
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/var/tmp folder hardeep_ubhi Linux - General 4 10-02-2006 07:10 AM
What is all this junk in the /tmp folder? HoosTrax Linux - Newbie 2 02-10-2004 04:03 PM
make my /tmp folder bigger? Kaiser Linux - General 3 12-17-2003 08:14 PM
How do I empty the /tmp folder at boot? Posty Slackware 13 10-12-2003 08:36 PM
tmp folder question synaptical Linux - General 8 08-31-2003 03:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration