How to list and remove files only if multiple conditions are met
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
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.
add a comment |
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
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 ofmp4files of each kind.
– P_Yadav
Jan 7 at 6:44
add a comment |
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
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
command-line bash python ruby
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.
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 ofmp4files of each kind.
– P_Yadav
Jan 7 at 6:44
add a comment |
2
Please provide sample names ofmp4files 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
add a comment |
1 Answer
1
active
oldest
votes
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_*
I wouldn't recommend doingmv, better doechowithout actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37
@SergiyKolodyazhnyy, yes.echo rm "$a"and deletingechoif happy, sounds like a good idea.
– JJoao
Jan 7 at 11:58
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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_*
I wouldn't recommend doingmv, better doechowithout actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37
@SergiyKolodyazhnyy, yes.echo rm "$a"and deletingechoif happy, sounds like a good idea.
– JJoao
Jan 7 at 11:58
add a comment |
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_*
I wouldn't recommend doingmv, better doechowithout actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37
@SergiyKolodyazhnyy, yes.echo rm "$a"and deletingechoif happy, sounds like a good idea.
– JJoao
Jan 7 at 11:58
add a comment |
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_*
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_*
answered Jan 7 at 9:21
JJoaoJJoao
1,38069
1,38069
I wouldn't recommend doingmv, better doechowithout actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37
@SergiyKolodyazhnyy, yes.echo rm "$a"and deletingechoif happy, sounds like a good idea.
– JJoao
Jan 7 at 11:58
add a comment |
I wouldn't recommend doingmv, better doechowithout actually renaming files
– Sergiy Kolodyazhnyy
Jan 7 at 11:37
@SergiyKolodyazhnyy, yes.echo rm "$a"and deletingechoif 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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
2
Please provide sample names of
mp4files of each kind.– P_Yadav
Jan 7 at 6:44