laite
laite

Reputation: 178

Running command recursively in linux

I'm trying to come up with a command that would run mp3gain FOLDER/SUBFOLDER/*.mp3 in each subfolder, but I'm having trouble understanding why this command doesn't work:

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

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

If I run command manually with mp3gain "./FOLDER/SUBFOLDER"/*.mp3 it works. What's going wrong?

Upvotes: 3

Views: 6267

Answers (4)

anon
anon

Reputation: 1

this works...

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

Upvotes: 0

noqqe
noqqe

Reputation: 172

If you have a fixed data structure like

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

and using zsh or bash version >=4.0 you could try

mp3gain **/*.mp3

But to make sure check the output of

ls **/*.mp3 

before you are getting serious with mp3gain.

Upvotes: 3

Giacomo1968
Giacomo1968

Reputation: 26066

Hmmm. Just tried this to test 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 see the file output for yourself:

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

Seems the quotes get in the way in your original command.

Upvotes: 0

NPE
NPE

Reputation: 500673

When you run mp3gain "./FOLDER/SUBFOLDER"/*.mp3 from your shell, the *.mp3 is getting expanded by the shell before being passed to mp3gain. When find runs it, there is no shell involved, and the *.mp3 is getting passed literally to mp3gain. The latter has no idea how to deal with wildcards (because normally it doesn't have to).

Upvotes: 1

Related Questions