Linux – Run commands recursively in Linux

Run commands recursively in Linux… here is a solution to the problem.

Run commands recursively in Linux

I’m trying to come up with a command that can run mp3gain FOLDER/SUBFOLDER/*.mp3 in every subfolder, but I can’t understand why this command doesn’t work:

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

When running, I get the error Can't open "./FOLDER/SUBFOLDER"/*.mp3 for reading for each folder and subfolder

IF I MANUALLY RUN THE COMMAND WITH MP3GAIN "./FOLDER/SUBFOLDER"/*.mp3, it works. What went wrong?

Solution

If you have a fixed data structure, like

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

And use zsh or bash version >=4.0 you can try

mp3gain **/*.mp3

But make sure to check

the output of

ls **/*.mp3 

Before you get serious about mp3gain.

Related Problems and Solutions