How can I convert my FLAC music collection to Apple Lossless?

avconv (or ffmpeg, which avconv is a fork of) can do this from the command line:

avconv -i input.flac -c:a alac output.m4a

It should preserve the metadata by itself.

To do every flac in a directory:

for f in ./*.flac; do avconv -i "$f" -c:a alac "${f%.*}.m4a"; done

To do every flac recursively (in the current directory and all sub-directories):

shopt -s globstar
for f in ./**/*.flac; do avconv -i "$f" -c:a alac "${f%.*}.m4a"; done

If you've got the flacs in ogg files or something, obviously change ./*.flac to ./*.ogg.

I think this should work with avconv/ffmpeg from the repositories (since ALAC is released under the Apache license, and can be legally distributed), though I have the version from medibuntu installed.

If you want to get rid of the original files, you can put rm into the loop. This version uses the -n flag for avconv, so it will not overwrite any already-existing ALAC files, and using && instead of ; means that if avconv stops with an error then the original FLAC file will not be deleted:

for f in ./*.flac; do avconv -n -i "$f" -c:a alac "${f%.*}.m4a" && rm "$f"; done

Note that deleting files with rm is irreversible (outside of forensic data recovery), so be careful using it.