1

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.

1 Answer 1

2

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.

1
  • 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, 2011 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .