views:

45

answers:

3

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?

A: 

simply use find

find . -type d -newermt "2010-03-31 0300" -and \( -not -newermt "2010-03-31 0310" \) -exec rm -rf {} \;
AlberT
+1  A: 

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
Didier Trosset
Running this gives the flag xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
Leda
+1  A: 

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