LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-05-2003, 05:51 AM   #1
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
cleaning up tmp directories


Is there a more beautiful way to check /tmp and /var/tmp is clean (= files that haven't been accessed in 72 hours are being automatically deleted). I think of running the following script as daily cron job:

Code:
#!/bin/sh

# clean up /tmp and /var/tmp

if [ -d /tmp -a -r /var/tmp ]
then
        find /tmp -type f -atime +3 -exec rm {} \;
        find /var/tmp -type f -atime +3 -exec rm {} \;
fi
 
Old 04-05-2003, 07:48 AM   #2
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
It is a little paranoid checking to see if /tmp is a directory and that the user has read permission to /var/tmp, but otherwise it will work.

The only other comment I have is that atime returns an integer and +3 means greater than 3 days which does not happen till 4 days or 96 hours (as 3.5 days access would truncate to 3 which is not greater than 3). But a 24 hour grace period shouldn't hurt. At least that is how is has always appeared to be implemented on my system.
 
Old 04-05-2003, 07:59 AM   #3
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Original Poster
Rep: Reputation: 46
Well one check more doesn't hurt. I could if it doesn't exist create it also ... or maybe add some sort of reporting and mail it to root :-)
 
Old 04-05-2003, 08:41 AM   #4
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
I noticed your signature, and no, it never hurts to be paranoid.

Why not the same checks on /tmp and /var/tmp?

if [ -d /tmp -a -r /tmp -a -d /var/tmp -a -r /var/tmp ]
 
Old 04-05-2003, 08:58 AM   #5
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Original Poster
Rep: Reputation: 46
uups now i know what i forgot :-) should double check next time before posting :-)
 
Old 09-10-2004, 03:26 AM   #6
BroX
Member
 
Registered: Oct 2003
Location: Sweden
Distribution: Slackware64-current, SlackwareARM-15.0
Posts: 833

Rep: Reputation: 90
What about directories?

I hate to wake up old threads, but since this little script was exactly what I was looking for I post my question here anyway.

Is there a reason not to include some lines to also remove directories that are found in /tmp or /var/tmp?

Cheers, Leon.
 
Old 09-10-2004, 05:15 AM   #7
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Re: What about directories?

Quote:
Originally posted by LJSBrokken
I hate to wake up old threads, but since this little script was exactly what I was looking for I post my question here anyway.

Is there a reason not to include some lines to also remove directories that are found in /tmp or /var/tmp?

Cheers, Leon.
Not really, just preferences really. I just have scripts on bootup to clean out all files in /tmp... I don't like to clean out this directory while the system is running, could accidently wipe out files that are in use
 
Old 09-19-2004, 11:57 AM   #8
fsbooks
Member
 
Registered: Jan 2002
Location: Missoula. Montana, USA
Distribution: Slackware (various)
Posts: 464

Rep: Reputation: 52
I do something like the following in my backup script:

find /tmp -depth -empty ! -mtime -99 -type d -exec rmdir {} \;

Only if a directory is empty and been unmodified for more than 99 days will it be removed.

My time is probably a bit excessive, it takes years to remove an entire build tree I may through in tmp because I don't think I need it but not quite ready to "rm -rf" it.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do recursive file delete using specifier (*.tmp) from nested directories? Arodef Linux - General 3 11-11-2009 07:49 AM
/var/ and /tmp/ directories puishor Linux - General 5 06-25-2005 08:36 AM
Root directories /tmp, /var, /etc ninmonkeys Linux - General 7 11-21-2004 01:49 PM
Cleaning up /var and /tmp.... Whitehat Linux - General 3 01-04-2004 07:07 PM
Numerous scb_*.tmp files in /tmp dburk Programming 3 08-18-2003 04:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:00 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