This is on ubuntu 18.04. I have access to bash, pip3, and ruby gems on this machine.

Trying to work with multiple mp4 files that were sent to us by VHS converter company. Each file has at least a version with 240p in the name and some of them have both a 240p filename and a 480p filename.

They stuck these hundreds of files in one zip and sent them to us.

If every mp4 file is in one directory, how could I find only the files that have both a 240p and a 480p version and remove the 240p version -- without removing the files that have ONLY a 240p version.

  • 2
    Please provide sample names of mp4 files of each kind. – Prvt_Yadav Jan 7 at 6:44

With bash, you could run something along the lines of

for a in *240p.mp4
   b=${a/240p/480p}                     ## replace 240 by 480
   if [ -f "$b" ]                       ## if x-480p.mp4 exists
     then   mv "$a" "REMOVE_$a"         ##   rename x-240p to REMOVE_x-240p

And if you are happy with the REMOVEd list

  • I wouldn't recommend doing mv, better do echo without actually renaming files – Sergiy Kolodyazhnyy Jan 7 at 11:37
  • @SergiyKolodyazhnyy, yes. echo rm "$a" and deleting echo if happy, sounds like a good idea. – user216043 Jan 7 at 11:58

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.