Something caused to damage some of my flac files, and to find out which ones I need to rerip, I would like to get a list containing only the damaged files.

How I do it now: Open a terminal in a directory, and enter: $ flac -t *.flac

The output of good files is something like:

Song1.flac: ok
Song2.flac: ok

On some of my old rips I get warnings, but the song seems to be okay:

Song3.flac: WARNING, cannot check MD5 signature since it was unset in the STREAMINFO
Song3.flac: ok 

But when an error occurs, the messages are something like:

Song4.flac: testing, 73% complete
Song4.flac: ERROR while decoding data
Song5.flac: ERROR while decoding data
Song6.flac: ERROR, MD5 signature mismatch                                          
Song7.flac: *** Got error code 0:FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC

Song7.flac: ERROR while decoding data

The FLAC stream may have been created by a more advanced encoder.  Try
  metaflac --show-vendor-tag Song7.flac
If the version number is greater than 1.2.1, this decoder is probably
not able to decode the file.  If the version number is not, the file
may be corrupted, or you may have found a bug.  In this case please
submit a bug report to
Make sure to use the "Monitor" feature to monitor the bug status.

My question is:

  • How can I filter the output to only show files with warnings (output contains WARNING) or errors (output contains ERROR)?

I think it might be doable with grep, but I don't know how to give the output of the flac -t command to grep. With flac -c

  • And if that works, how can I check all subdirs at once?

My music collection is sorted into many subdirs and going to every dir and run the command would be laborious.

Bonus points if it could output the path of the corrupt file, not only the name :)


Using bash 4's globstar, this will recursively find all flac files from the current directory, and output the error code and filename for the ones with errors and warnings.

#!/usr/bin/env bash
shopt -s globstar

for file in ./**/*.flac; do
    flac -wst "$file" 2>/dev/null || printf '%3d %s\n' "$?" "$file"

The manual does not document what error codes it exits with for different types of errors, therefore I added the error code in the output, maybe you can see a pattern from it.

  • That seems to be the solution. Thank you! Could you please explain what the fourth line in your code does? It seems the error code is alway 1 both for the warnings and errors – shaddow Jul 23 '12 at 19:36
  • You mean for file in ./**/*.flac; do? When globstar is enabled with shopt -s globstar, ** will match all files and directories recursively. See Pattern Matching – geirha Jul 23 '12 at 19:42
  • No, I meant the following 5th line, sorry, I didn't count the empty line ;) – shaddow Jul 23 '12 at 19:54
  • @shaddowy2, cmd1 || cmd2 runs cmd1, and if cmd1 fails (returns exit status != 0), it runs cmd2. If cmd1 succeeds (returns exit status == 0), it does not run cmd2. So flac ... || printf ... is a shorthand for if ! flac ...; then printf...; fi – geirha Jul 23 '12 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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