Executing a command recursively on Linux

I am trying to come up with a command that will run mp3gain FOLDER/SUBFOLDER/*.mp3

in each subfolder, but I am having a hard time understanding why this command is not working:

find . -type d -exec mp3gain \"{}\"/*.mp3 \;

      

On startup, I get an error Can't open "./FOLDER/SUBFOLDER"/*.mp3 for reading

for every folder and subfolder.

If I run the command manually with mp3gain "./FOLDER/SUBFOLDER"/*.mp3

, it works. What's wrong?

+3


source to share


4 answers


When you run mp3gain "./FOLDER/SUBFOLDER"/*.mp3

from your shell, it is *.mp3

expanded by the shell before passing it to mp3gain

. When it find

starts up, the shell is not involved, but *.mp3

literally passed to mp3gain

. The latter doesn't know how to deal with wildcards (because it usually isn't necessary).



+1


source


If you have a fixed data structure like

folder1/subfolder1/
folder1/subfolder2/
folder2/subfolder1/
[...]

      

and using zsh

or bash version >=4.0

, you can try

mp3gain **/*.mp3

      



But to test the output

ls **/*.mp3 

      

before you start getting serious about mp3gain.

+3


source


Hmmm. Just tried this to check how the directory is parsed by replacing mp3gain

with echo

and it works:

find . -type d -exec echo {}\/\*.mp3 \;

      

Try running your version of the command, but with echo

, to view the file for yourself:

find . -type d -exec echo \"{}\"/*.mp3 \;

      

It seems the quotes are getting into your original command.

0


source


it works...

find /music -name *mp3 -exec mp3gain -r -k {} \;

      

0


source







All Articles