Jan 042013

This isn’t elegant at all, but it is an easy and adaptable way to delete lots of files in a directory.

First, get the list, using grep (if the file-names have a sort-of-pattern) and/or ls -lt (if the files are grouped by date).

Next, copy the list (click-and-drag), open up vim (emacs), and paste the info to create a text file. If you were sorting with ls -lt you will have a lot more info than the file name. You can use awk ‘{print $whateverColumnNumber}’ file.txt > new_file.txt to create a text file with just the file names.

Then you can simply use a loop in bash:

while read p; do rm $p; done < new_file.txt

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>