How to run command recursively on files within directory and sub-directories within?
How can I run the command below recursively on all directories and sub-directories within?
[someone@someones-pc ~]$ for i in *.mp4; do ffmpeg -i "$i" -i watermark.png -filter_complex "overlay=1623:25" /output/directory/"${i%.*}.mp4"; done
Right now the above command will only search for all .mp4's within the chosen directory and run the command(s) on them, however if I have another directory or deeper sub-directories containing more .mp4's this will not find them. How can I alter this command to run on other .mp4's that are also in other sub-directories and possibly even deeper within?
EDIT: (found this here on stackexchange)
How can this script be edited to work with my FFmpeg command above?
#!/bin/bash
WM=$HOME/public_html/image/catalog/logo-website/watermark.png # This is the path to your watermark image
SCALE=100 # This sets the scale % of your watermark image
STARTDIR="/home/whatever/images" # This is the directory to start in
for imagedir in $( find $STARTDIR -type d )
do
echo "Running in $imagedir ..."
cd $imagedir
file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
do
echo "Watermarking $IMAGE"
composite -dissolve 40% -gravity SouthEast -quality 100 ( $WM -resize $SCALE% ) "$IMAGE" "$IMAGE"
done
done
UPDATE:
I am not saying this has to be a "find" command, I was was referring to my "ffmpeg" command when I asked how can this script be edited to work with my command, not the find command. Duh. All I care about is running my ffmpeg command on my files recursively.
NOT A DUPLICATE QUESTION BECAUSE:
I believe my question is not a duplicate because of how impossible it is to find an answer to my question on StackExchange. My question is targeted more clearly to new Linux learners and will be found much better to new and average people trying to learn. If you look at the so-called duplicate question title below, its not something any new or even average Linux user would be searching for. Also it says nothing about running commands recursively on files within directories and sub-directories, and that is something the less advanced would be asking. I believe my question is helpful to new learners of this community.
"For loop in Unix : including files from sub directories"
linux command-line files command recursive
add a comment |
How can I run the command below recursively on all directories and sub-directories within?
[someone@someones-pc ~]$ for i in *.mp4; do ffmpeg -i "$i" -i watermark.png -filter_complex "overlay=1623:25" /output/directory/"${i%.*}.mp4"; done
Right now the above command will only search for all .mp4's within the chosen directory and run the command(s) on them, however if I have another directory or deeper sub-directories containing more .mp4's this will not find them. How can I alter this command to run on other .mp4's that are also in other sub-directories and possibly even deeper within?
EDIT: (found this here on stackexchange)
How can this script be edited to work with my FFmpeg command above?
#!/bin/bash
WM=$HOME/public_html/image/catalog/logo-website/watermark.png # This is the path to your watermark image
SCALE=100 # This sets the scale % of your watermark image
STARTDIR="/home/whatever/images" # This is the directory to start in
for imagedir in $( find $STARTDIR -type d )
do
echo "Running in $imagedir ..."
cd $imagedir
file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
do
echo "Watermarking $IMAGE"
composite -dissolve 40% -gravity SouthEast -quality 100 ( $WM -resize $SCALE% ) "$IMAGE" "$IMAGE"
done
done
UPDATE:
I am not saying this has to be a "find" command, I was was referring to my "ffmpeg" command when I asked how can this script be edited to work with my command, not the find command. Duh. All I care about is running my ffmpeg command on my files recursively.
NOT A DUPLICATE QUESTION BECAUSE:
I believe my question is not a duplicate because of how impossible it is to find an answer to my question on StackExchange. My question is targeted more clearly to new Linux learners and will be found much better to new and average people trying to learn. If you look at the so-called duplicate question title below, its not something any new or even average Linux user would be searching for. Also it says nothing about running commands recursively on files within directories and sub-directories, and that is something the less advanced would be asking. I believe my question is helpful to new learners of this community.
"For loop in Unix : including files from sub directories"
linux command-line files command recursive
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
1
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago
add a comment |
How can I run the command below recursively on all directories and sub-directories within?
[someone@someones-pc ~]$ for i in *.mp4; do ffmpeg -i "$i" -i watermark.png -filter_complex "overlay=1623:25" /output/directory/"${i%.*}.mp4"; done
Right now the above command will only search for all .mp4's within the chosen directory and run the command(s) on them, however if I have another directory or deeper sub-directories containing more .mp4's this will not find them. How can I alter this command to run on other .mp4's that are also in other sub-directories and possibly even deeper within?
EDIT: (found this here on stackexchange)
How can this script be edited to work with my FFmpeg command above?
#!/bin/bash
WM=$HOME/public_html/image/catalog/logo-website/watermark.png # This is the path to your watermark image
SCALE=100 # This sets the scale % of your watermark image
STARTDIR="/home/whatever/images" # This is the directory to start in
for imagedir in $( find $STARTDIR -type d )
do
echo "Running in $imagedir ..."
cd $imagedir
file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
do
echo "Watermarking $IMAGE"
composite -dissolve 40% -gravity SouthEast -quality 100 ( $WM -resize $SCALE% ) "$IMAGE" "$IMAGE"
done
done
UPDATE:
I am not saying this has to be a "find" command, I was was referring to my "ffmpeg" command when I asked how can this script be edited to work with my command, not the find command. Duh. All I care about is running my ffmpeg command on my files recursively.
NOT A DUPLICATE QUESTION BECAUSE:
I believe my question is not a duplicate because of how impossible it is to find an answer to my question on StackExchange. My question is targeted more clearly to new Linux learners and will be found much better to new and average people trying to learn. If you look at the so-called duplicate question title below, its not something any new or even average Linux user would be searching for. Also it says nothing about running commands recursively on files within directories and sub-directories, and that is something the less advanced would be asking. I believe my question is helpful to new learners of this community.
"For loop in Unix : including files from sub directories"
linux command-line files command recursive
How can I run the command below recursively on all directories and sub-directories within?
[someone@someones-pc ~]$ for i in *.mp4; do ffmpeg -i "$i" -i watermark.png -filter_complex "overlay=1623:25" /output/directory/"${i%.*}.mp4"; done
Right now the above command will only search for all .mp4's within the chosen directory and run the command(s) on them, however if I have another directory or deeper sub-directories containing more .mp4's this will not find them. How can I alter this command to run on other .mp4's that are also in other sub-directories and possibly even deeper within?
EDIT: (found this here on stackexchange)
How can this script be edited to work with my FFmpeg command above?
#!/bin/bash
WM=$HOME/public_html/image/catalog/logo-website/watermark.png # This is the path to your watermark image
SCALE=100 # This sets the scale % of your watermark image
STARTDIR="/home/whatever/images" # This is the directory to start in
for imagedir in $( find $STARTDIR -type d )
do
echo "Running in $imagedir ..."
cd $imagedir
file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
do
echo "Watermarking $IMAGE"
composite -dissolve 40% -gravity SouthEast -quality 100 ( $WM -resize $SCALE% ) "$IMAGE" "$IMAGE"
done
done
UPDATE:
I am not saying this has to be a "find" command, I was was referring to my "ffmpeg" command when I asked how can this script be edited to work with my command, not the find command. Duh. All I care about is running my ffmpeg command on my files recursively.
NOT A DUPLICATE QUESTION BECAUSE:
I believe my question is not a duplicate because of how impossible it is to find an answer to my question on StackExchange. My question is targeted more clearly to new Linux learners and will be found much better to new and average people trying to learn. If you look at the so-called duplicate question title below, its not something any new or even average Linux user would be searching for. Also it says nothing about running commands recursively on files within directories and sub-directories, and that is something the less advanced would be asking. I believe my question is helpful to new learners of this community.
"For loop in Unix : including files from sub directories"
linux command-line files command recursive
linux command-line files command recursive
edited 29 mins ago
Anonymous User
asked 1 hour ago
Anonymous UserAnonymous User
144
144
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
1
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago
add a comment |
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
1
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
1
1
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
});
}
});
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%2funix.stackexchange.com%2fquestions%2f501110%2fhow-to-run-command-recursively-on-files-within-directory-and-sub-directories-wit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- 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%2funix.stackexchange.com%2fquestions%2f501110%2fhow-to-run-command-recursively-on-files-within-directory-and-sub-directories-wit%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
Can it be? Yes. Should it be? No - see Why is looping over find's output bad practice? for example (which also describes some alternatives)
– steeldriver
1 hour ago
Why would I care about the "find" command? That's not my focus.
– Anonymous User
40 mins ago
1
Possible duplicate of For loop in Unix : including files from sub directories
– Jeff Schaller
40 mins ago
The point of "duplicate" isn't to say your question is bad. Indeed, we can keep your question around so that people can find what you asked for, and then be directed to a good answer. Many good questions can have the same answer. We just don't want to duplicate answers.
– Stephen Harris
13 mins ago