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.
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.
The syntax is a little bit tricky:
find ./directory -name "*.srt" -exec rm {} \;
-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.
– Kamil Maciorowski
Jun 09 '17 at 17:04
-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
– Eric Renouf
Jun 09 '17 at 17:56
find TV_Recordings/ -name "*.srt" -delete
– Widgeteye
Jun 09 '17 at 18:01
*.srtto avoid shell globbing. Without the quotes it will work as you expect only when there are no*.srtfiles in the current directory. – Kamil Maciorowski Jun 09 '17 at 16:57