Ubuntu – Convert all .ape files to .flac in different subfolders

avconvcommand lineformat conversion

I was trying to convert some .ape files to .flac files using avconv on command line; obviously, avconv is not the main point here; its syntax is pretty straightforward, avconv -i inputApeFile.ape outputFlacFile.flac.

The point is that the files are nested in more subfolders; i.e., I have the Artist folder, then various CD subfolders, each of one contain different .ape files.
How can I convert all the files and then save them in the same folder of the original file but with the .flac extension?

If it is possible, I'd like to use only shell command on a single line without using scripts. I think it should be something like that

avconv -i 'ls -R | grep ape' '???'

but I'm stuck with the second part (maybe using sed??!?)

Best Answer

The command that you need is:

find /path/to/MainDir/ -type f -name "*.ape"  -execdir sh -c ' avconv -i "$1" "${1%.ape}.flac" ' _ {} \;

This will find each file that has .ape suffix and then convert it with the same filename with .flac suffix to the same location as original file is located.

{} is the path of current found file.
See the test from here