Search code examples
linuxtimesortingdebianrm

Remove files created between certain time stamps.


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?


Solution

  • 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