Remove files created between certain time stamps.

user271528 picture user271528 · Apr 1, 2010 · Viewed 11k times · Source

Last night I had a script go a bit crazy and create a bunch of directories between 3:00 and 3:09am. Is there a quick one liner that will hunt these down and remove them for me?

Answer

Didier Trosset picture Didier Trosset · Apr 1, 2010

If you can search for the first and last (chronological) directories you want to delete, then you can use find:

find . -newer first -not -newer last -type d

And if the output suits you, go for the delete

find . -newer first -not -newer last -type d -print0 |  xargs -0 rmdir

or with explicit date stamps:

find . -newermt "2010-03-31 0300" -not -newermt "2010-03-31 0310" -type d