How to list and remove files only if multiple conditions are met












1














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.










share|improve this question







New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




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


















1














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.










share|improve this question







New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 2




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
















1












1








1







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.










share|improve this question







New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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.







command-line bash python ruby






share|improve this question







New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Jan 7 at 6:02









S JenkinsS Jenkins

61




61




New contributor




S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






S Jenkins is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 2




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
















  • 2




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










2




2




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






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












1 Answer
1






active

oldest

votes


















0














With bash, you could run something along the lines of



for a in *240p.mp4
do
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
fi
done


And if you are happy with the REMOVEd list



rm REMOVE_*





share|improve this answer





















  • 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.
    – JJoao
    Jan 7 at 11:58













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






S Jenkins is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107615%2fhow-to-list-and-remove-files-only-if-multiple-conditions-are-met%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














With bash, you could run something along the lines of



for a in *240p.mp4
do
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
fi
done


And if you are happy with the REMOVEd list



rm REMOVE_*





share|improve this answer





















  • 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.
    – JJoao
    Jan 7 at 11:58


















0














With bash, you could run something along the lines of



for a in *240p.mp4
do
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
fi
done


And if you are happy with the REMOVEd list



rm REMOVE_*





share|improve this answer





















  • 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.
    – JJoao
    Jan 7 at 11:58
















0












0








0






With bash, you could run something along the lines of



for a in *240p.mp4
do
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
fi
done


And if you are happy with the REMOVEd list



rm REMOVE_*





share|improve this answer












With bash, you could run something along the lines of



for a in *240p.mp4
do
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
fi
done


And if you are happy with the REMOVEd list



rm REMOVE_*






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 7 at 9:21









JJoaoJJoao

1,38069




1,38069












  • 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.
    – JJoao
    Jan 7 at 11:58




















  • 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.
    – JJoao
    Jan 7 at 11:58


















I wouldn't recommend doing mv, better do echo without actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37




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.
– JJoao
Jan 7 at 11:58






@SergiyKolodyazhnyy, yes. echo rm "$a" and deleting echo if happy, sounds like a good idea.
– JJoao
Jan 7 at 11:58












S Jenkins is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















S Jenkins is a new contributor. Be nice, and check out our Code of Conduct.













S Jenkins is a new contributor. Be nice, and check out our Code of Conduct.












S Jenkins is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107615%2fhow-to-list-and-remove-files-only-if-multiple-conditions-are-met%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Category:香港粉麵

List *all* the tuples!

Channel [V]