1

I'm generating a list of files and folder that meet certain criteria with use of a command:

find ~/ -iname "whatIwantToRemove"

The command will generate some results:

/Users/me//.Trash/whatIwantToRemove
...

I would like to be able to automatically delete all of those files.


Possible solution

I'm looking at a similar discussion on Unix and Linux and was wondering whether the command would work:

find . -type f -regex '/ex/' -exec rm {} \;
3

What's wrong with the -delete flag?

find ~/ -iname "whatIwantToRemove" -delete
  • Nothing, just my reflex to Google things first. Actually: sudo find your-directory/ -name 'mytrash' -delete seems to work – Konrad Dec 3 '15 at 20:01
  • I used this with a bunch of file copies I had that all had "whatever (1).jpg", "whatever (2).jpg" etc. filenames. I riffed on your command to get an idea of the files to be deleted: find . -iname "*(*)*" | wc -l Then I deleted with your command. find . -iname "*(*)*" -delete Thanks! – Chris Smith Sep 4 '17 at 0:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .