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
.
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
The syntax is a little bit tricky:
find ./directory -name "*.srt" -exec rm {} \;
1it'd be nicer to use -delete – djsmiley2k TMW – 2017-06-09T17:00:40.583
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. – Kamil Maciorowski – 2017-06-09T17:04:14.917
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 – Eric Renouf – 2017-06-09T17:56:10.300
Here's what I used and it worked fine. Thanks to all those who answered and commented: find TV_Recordings/ -name "*.srt" -delete
– Widgeteye – 2017-06-09T18:01:42.720
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. – Kamil Maciorowski – 2017-06-09T16:57:31.297