0

I have directories with sub directories containing .srt files. I need to go through the directories and delete them all. I know how to find them like so:

find ./directory -name *.srt

but I'm not sure how to pipe them to rm.

1
  • First of all you should quote *.srt to avoid shell globbing. Without the quotes it will work as you expect only when there are no *.srt files in the current directory. Jun 9, 2017 at 16:57

1 Answer 1

1

The syntax is a little bit tricky:

find ./directory -name "*.srt" -exec rm {}  \;
4
  • 1
    it'd be nicer to use -delete Jun 9, 2017 at 17:00
  • 1
    -exec rm {} \; spawns rm for every file. -exec rm {} + removes many files at once; -delete is the best because it doesn't create new processes, I believe. Jun 9, 2017 at 17:04
  • 1
    @djsmiley2k though -delete isn't strictly portable, though BSD and GNU both support it. It isn't specified in POSIX though, but if you've got it that's the way to go Jun 9, 2017 at 17:56
  • Here's what I used and it worked fine. Thanks to all those who answered and commented: find TV_Recordings/ -name "*.srt" -delete
    – Widgeteye
    Jun 9, 2017 at 18:01

You must log in to answer this question.

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