Question

I wish to have a command or script that will execute the test feature of flac on all flac files in a folder and its sub-folders. (i.e. $ flac -t music_file.flac)

I've tried using

find . -name "*.flac" -exec flac -t '{}' \;

and it works, however the flac test function also writes a copyright/warranty output before testing each file, making it difficult to clearly see the result of 'ok'.

I've also tried using

for file in 'ls *.flac'
do
  flac -t $file
done

which works much neater (only writes the warranty/copyright statement once initially) but does not recursively act on sub-folders.

Could I request some help in improving this?

Was it helpful?

Solution

I'm not sure if it's the most an elegant solution, but you can use your original command with grep to exclude bits you don't want. So if you wanted the list of files that were tested along with the status, you could search for:

find -name "*.flac" -exec flac -t '{}' \; |& grep "\.flac"

'&' is important since it seems flac outputs most stuff to stderr.

OTHER TIPS

You can pass --silent/-s to flac and it will not include the copyright info, etc., in the output. Note, however, that it will also not show anything when the file is ok, only outputting if it is not ok.

-R, --recursive  list subdirectories recursively

You can try this:

for file in 'ls -R *.flac'
do
    flac -t $file
done

I get no credit for this, but I think I found a command here which seems to do exactly what the orginal poster wants and which works better for me than the ones proposed here.

find -type f -iname '*.flac' -print0 | xargs --null flac -t

One quibble with this command is that in the one instance I've tested so far, it processes the files in a seemingly random order. (But the same was true with the commands here.) Also, if there are very many files, I'm not sure it will be easy to spot the errors among all the okays. The author of the command recommends adding -w and -s switches to suppress everything except errors, but that seems to be just what the original poster wants to get away from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top