You are not logged in.
I need to apply mp3gain (album mode) to all mp3 files in a given directory. Each album is in its own directory under /media/data/music/albums for example:
/media/data/music/albums/foo
/media/data/music/albums/bar
/media/data/music/albums/moreWhat needs to happen is:
cd /media/data/music/albums/foo && mp3gain -a -k -p *.mp3
cd /media/data/music/albums/bar && mp3gain -a -k -p *.mp3
cd /media/data/music/albums/more && mp3gain -a -k -p *.mp3I want to use find and xargs to do this but am unsure how to craft the right syntax. I have used the this construct to accomplish tasks like this before, but this won't do both the cd into the dir and then run the mp3gain command.
find /media/data/music/album -type d -print0 | xargs -0 cd {} && mp3gain -a -k -p *.mp3Thanks!
Last edited by graysky (2012-03-01 21:07:28)
Offline
Why do you need the "cd"? This seems to be working okay for me:
find ~/Music/Nile -type f -regex ".*\.mp3$" -exec mp3gain -a -k -p {} +Offline
Hmm... without the cd command, I believe you can't use 'album' mode since mp3gain understands all files in a given directory are part of the same album.
Offline
Offline
There exists execdir, which does the same as exec, but the command is executed from the subdirectory. I've never tried it though.
Offline
There exists execdir, which does the same as exec, but the command is executed from the subdirectory. I've never tried it though.
Correct, but you won't be able to make a glob expand properly without starting up a shell in that directory:
find /foo/bar/baz -type d -execdir bash -c 'mp3gain -a -k -p *.mp3' _ {} \;...at which point, you're forced to create a new shell for each invocation. You could do it all at once:
find /foo/bar/baz -type d -exec bash -c 'for d in "$@"; do pushd "$d"; mp3gain -a -k -p *.mp3; popd; done' _ {} +...but then you're just doing the exact same thing as the straight up for loop if its only a single directory deep.
Offline
I like the idea of a for loop. Here is a variation on the theme:
find /media/data/music/albums -type d | while read dir; do cd "$dir" && mp3gain -a -k -p *.mp3; doneOffline