Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: rm old directory

by shoness (Friar)
on Jul 22, 2008 at 20:30 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2020-10-27 18:20 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (257 votes). Check out past polls.