1

So I made this script Convert videos recursively with handbrake.

And it uses this command as an option

find . -name '*.mkv' -exec rm -r {} \;

But i made this new script, for removing audio streams recursively Remove Audio Streams of videos - recursively without converting audio or video with FFMPEG

But I would like to add the option to remove all *.mkv files EXCEPT ones that are *FINAL.mkv as that is the output my second script uses for the files.

Could somebody help real quick, I'm not very good at coding, I can just manipulate it very well and understand it :P

2

To remove all mkv files recursively except FINAL.mkv you can do :

find . -type f -not -name '*FINAL.mkv' -name '*.mkv' -delete
  • Use -type f to search for only files

  • -name '*.mkv' will get us all .mkv files

  • -not -name '*FINAL.mkv' will leave out all the *FINAL.mkv files

  • -delete will remove the files found.

Also do a dry run by the following at first to check that everything is all right :

find . -type f -not -name 'FINAL.mkv' -name '*.mkv'
  • can I ask why the code I found uses -exec rm -r {} \; instead of -delete? – FreeSoftwareServers Aug 13 '15 at 6:28
  • @FreeSoftwareServers thats a clumsy way of doing what -delete does, also -r is redundant with rm as we are dealing with files only..-exec rm -r {} \; will spawn an extra process rm for every file, it will be a improvement of -exec rm -r {} \; if -exec rm {} + was being used.. – heemayl Aug 13 '15 at 6:31
  • and to sum up your previous comment altho -exec rm {} + is an improvement, i am better off using -delete anyway – FreeSoftwareServers Aug 13 '15 at 6:34
  • @FreeSoftwareServers Yeah..i did not look the *FINAL.mkv glob you wanted..fixed.. – heemayl Aug 13 '15 at 6:38
  • would it be to much to ask for second bit of code that renamed all remaining files the same name without the word FINAL?, I can give you credit in the script im creating for the help with the perfections, im all about automation, but I can start a new thread or research more if not. – FreeSoftwareServers Aug 13 '15 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.