Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: rm old directory

by shoness (Friar)
on Jul 22, 2008 at 20:30 UTC ( [id://699418]=note: print w/replies, xml ) Need Help??


in reply to rm old directory

unix%> /usr/bin/find . -type d -mtime +60 -exec /bin/rm -rf {} \;
  • replace "." with the directory you want to search below
  • "-type d" says "directories"
  • "-mtime +60" says "not modified in 60 days" (also consider "-atime" for "last accessed (aka "read") time" or "-ctime" for "change time", depending on how you measure "age".)
  • "-exec" passes matching directory names to "/bin/rm -rf".

Edited: per moritz's suggestion, recommend "mtime" instead of "atime" although it's all up to you...

Replies are listed 'Best First'.
Re^2: rm old directory
by moritz (Cardinal) on Jul 22, 2008 at 20:56 UTC
    Relying on atime is generally a bad idea. I for one disable atime tracking during mounting, because IMHO it's a bad idea to have a side effect from every read.

    On my box your script would thus remove many directories that should stay.

    So rather rely on mtime.

      This is probably an edge case, but we had a tftp directory that we were cleaning up based on last modified time. The problem we ran into is that Windows/Samba and Konqueror all maintained the original timestamps on the file. So when someone copied a file created back in 2006 over to the system it got deleted fairly quickly!

      Our workaround was to make sure the files were not being backed up and then use the last access time instead of the last modified time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://699418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-03-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found