Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I use the following loop to do .flac --> .mp3 transcoding:

for file in *.flac; do $(flac -cd "$file" | lame --preset fast extreme - "${file%.flac}.mp3"); done

The directory, of course, must contain .flac files for this to work. What I'd like to be taught is the syntax in order to make this command work recursively. The aim is to cd to the directory containing all the subdirectories of .flac files and have the command loop through them all.

Thanks a lot in advance.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

Create a file ~/bin/flac2mp3 with the contents:

#!/bin/bash
file="$1"
flac -cd "$file" | lame --preset fast extreme - "${file%.flac}.mp3"

Then run find . -name '*.flac' -exec ~/bin/flac2mp3 '{}' \;

It can be done without using a separate file for ~/bin/flac2mp3 but I think using a separate file is simpler and more clear.

share|improve this answer
    
Thanks so much. Works a charm. I never would have worked this out by myself. I might just add (for those that land here via Google) that the file flac2mp3 needs to be made executable by doing $ chmod +x flac2mp3. This has really made my day, and possibly even my year. –  boehj Mar 27 '11 at 10:39
    
You're welcome. –  Jordan Uggla Mar 27 '11 at 22:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.