LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 10-19-2009, 02:21 PM   #1
mejohnsn
Member
 
Registered: Sep 2009
Posts: 174

Rep: Reputation: Disabled
How and When to delete files in /tmp?


I am mystified by the files accumulating in /tmp. I have been running Fedora11 for just a few weeks, but I already have 2832K of files in there.

I thought the programs that created files in /tmp were responsible for deleting them when done. But clearly, that is not happening, at least not always.

So the question is: when is it safe for me to delete them? Or is there some reason these programs are failing to delete them themselves, and some way for me to fix that?
 
Old 10-19-2009, 02:27 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975Reputation: 1975
2823K? who cares about 2.3 megabytes of temp files?

/tmp is generally a tmpfs filesystem, which is an in-memory filesystem which will not persist a reboot. Files won't necessarily clear themselves up, but there's very seldom anything interesting in there, just lock files and such, unless you use it for other files, which you're perfectly entitled to.
 
Old 10-19-2009, 02:33 PM   #3
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
I would advise against apatch to security around /tmp. While normal files are ignorable, /tmp itself is the target of things like rootkits... I am in the opinion that /tmp should always be a seperate partition with noexec, nosuid and nodev options active, even on desktops. I have seen a number of rootkitted machines with scripts in /tmp....
 
Old 10-19-2009, 07:06 PM   #4
SharpyWarpy
Member
 
Registered: Feb 2003
Location: Florida
Distribution: Fedora 18
Posts: 862

Rep: Reputation: 90
Speaking for myself, I have deleted files in the /tmp directory many times with no problems at all. 2mb might not seem like much these days but I still remember running with a 120mb hard drive some years back and I got in the habit of cleaning stuff up all the time and I still do. It makes me feel better.
 
Old 10-20-2009, 03:53 AM   #5
mejohnsn
Member
 
Registered: Sep 2009
Posts: 174

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
I would advise against apatch to security around /tmp. While normal files are ignorable, /tmp itself is the target of things like rootkits... I am in the opinion that /tmp should always be a seperate partition with noexec, nosuid and nodev options active, even on desktops. I have seen a number of rootkitted machines with scripts in /tmp....
That's nice, but what has "a patcfh to security" got to do with the questions?
 
Old 10-20-2009, 04:00 AM   #6
mejohnsn
Member
 
Registered: Sep 2009
Posts: 174

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
2823K? who cares about 2.3 megabytes of temp files?

/tmp is generally a tmpfs filesystem, which is an in-memory filesystem which will not persist a reboot. Files won't necessarily clear themselves up, but there's very seldom anything interesting in there, just lock files and such, unless you use it for other files, which you're perfectly entitled to.
Generally? Well, now that you mention it, I see the Install CD that made the decision to mount /tmp as /dev/shm, which sounds like "shared memory". Yet it is most certainly persisting past reboots.

As for what is in there, I am seeing PDF files I chose to view instead of download in Firefox -- and lost of files like "virtual-mejohnsn.Sj4G9C".
 
Old 10-20-2009, 04:01 AM   #7
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by mejohnsn View Post
...
So the question is: when is it safe for me to delete them? Or is there some reason these programs are failing to delete them themselves, and some way for me to fix that?
I can't specifically speak for a Fedora system, but on my Slack system, if I want to clear out /tmp I switch to init 1 before a reboot, delete everything in there, and reboot.

Much of the stuff in there will come back over time, depending on system usage; as mentioned, there are lock files and odds and ends and stuff that get created on a regular basis, but aren't necessarily deleted by whatever creates them with any regularity.

For the record, my /tmp persists over reboots too.

Sasha

Last edited by GrapefruiTgirl; 10-20-2009 at 04:02 AM.
 
Old 10-20-2009, 01:56 PM   #8
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

Rep: Reputation: 197Reputation: 197
If it's in /tmp and you reboot you shouldn't expect it to be there. So you can delete the contents early in the boot process or late in the shutdown process.

SUSE distros have a setting CLEAR_TMP_DIRS_AT_BOOTUP in /etc/sysconfig/cron that you can set to "yes" and that will delete any files in /tmp that don't belong to root whenever you reboot. Does Fedora have something equivalent to that? A quick Google didn't bring up anything.

Have you got a file /etc/init.d/halt.local ? If so you should put something like 'cd /tmp && rm -rf *' in there.
 
Old 10-20-2009, 02:29 PM   #9
mostlyharmless
Senior Member
 
Registered: Jan 2008
Distribution: Arch/Slackware/Knoppix
Posts: 1,776
Blog Entries: 14

Rep: Reputation: 274Reputation: 274Reputation: 274
Slackpackages I make are all placed in /tmp prior to installing them; if you want to reinstall one of those without recompiling it you might want to save those elsewhere prior to wiping /tmp
 
Old 10-20-2009, 02:48 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,354
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by mejohnsn View Post
So the question is: when is it safe for me to delete them? Or is there some reason these programs are failing to delete them themselves, and some way for me to fix that?
Simple question, simple answer, see: tmpwatch.
 
Old 10-20-2009, 03:12 PM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
For a system that is booted regularly are there and reasons for not deleting everything in /tmp as soon as it is mounted? I've modified /etc/rc.d/rc.S (this on Slackware 13.0) changing this original line
Code:
 ( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )
to
Code:
( cd /tmp && rm -rf * )
No breakage so far. On long uptime systems I used to remove anything more than 7 days old from a daily cron job. Half-expected some breakage but never had any.
 
Old 10-20-2009, 04:45 PM   #12
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
Originally Posted by mejohnsn View Post
That's nice, but what has "a patcfh to security" got to do with the questions?
Well good spelling would help, it doesn't directly relate the question, I was pointing out that a statement of 'it's /tmp it doesn't matter' is extremely bad behaviour considering how exploitable /tmp can be.
 
Old 10-21-2009, 05:33 PM   #13
mejohnsn
Member
 
Registered: Sep 2009
Posts: 174

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by catkin View Post
For a system that is booted regularly are there and reasons for not deleting everything in /tmp as soon as it is mounted? I've modified /etc/rc.d/rc.S (this on Slackware 13.0) changing this original line
Code:
 ( cd /tmp && rm -rf kde-[a-zA-Z]* ksocket-[a-zA-Z]* hsperfdata_[a-zA-Z]* plugtmp* )
to
Code:
( cd /tmp && rm -rf * )
No breakage so far. On long uptime systems I used to remove anything more than 7 days old from a daily cron job. Half-expected some breakage but never had any.
But why is this procedure better than using 'tmpwatch' in a cron job??
 
Old 10-21-2009, 05:35 PM   #14
mejohnsn
Member
 
Registered: Sep 2009
Posts: 174

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by r3sistance View Post
Well good spelling would help, it doesn't directly relate the question, I was pointing out that a statement of 'it's /tmp it doesn't matter' is extremely bad behaviour considering how exploitable /tmp can be.
I agree that that is an important point. So despite your (ahem!) complaint about the typo, I clicked on the blue thumb.
 
Old 10-23-2009, 03:36 PM   #15
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by mejohnsn View Post
But why is this procedure better than using 'tmpwatch' in a cron job??
It's not better, just an alternative (and I like solutions that don't require installing another package).
 
  


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
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM
script to delete tmp files Iyyappan Linux - Newbie 8 08-02-2009 06:40 AM
Slackbuild files in /tmp. Ok to delete? Romanus81 Slackware 9 11-05-2008 09:45 PM
How To Delete tmp Files In FC5 zenarcher Fedora 3 09-07-2006 12:51 AM
can i delete /tmp files? demmylls Linux - General 1 03-01-2004 10:14 AM

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

All times are GMT -5. The time now is 11:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration