6

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?

SherylHohman
  • 16,580
  • 17
  • 88
  • 94

3 Answers3

6

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
caf
  • 233,326
  • 40
  • 323
  • 462
Didier Trosset
  • 36,376
  • 13
  • 83
  • 122
  • Running this gives the flag xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option –  Apr 01 '10 at 13:05
1

you can try this, if you are working in just one directory and the 5th field of the ls -ltrog output is the time.

ls -ltrog | awk '$5~/03:0[0-9]/{$1=$2=$3=$4=$5="";gsub("^ +",""); cmd="rm \047"$0"\047";system(cmd) }'
ghostdog74
  • 327,991
  • 56
  • 259
  • 343
0

simply use find

find . -type d -newermt "2010-03-31 0300" -and \( -not -newermt "2010-03-31 0310" \) -exec rm -rf {} \;
drAlberT
  • 22,059
  • 5
  • 34
  • 40