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?
source to share
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).
source to share
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.
source to share