Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several folders with both FLAC 24/96 and 16/44.1 files.

I want to delete the 24-bit/96 KHz files, but leave the others. How do I do this from the command line? Is there a way to systematically sort files by metadata and then use that list with rm?

share|improve this question
up vote -2 down vote accepted

For the sake of completeness, it's worth too mention that it's also very easy to open a directory and it's subdirectories in Puddletag, sort for your desired criteria, and then mark and delete the files you want. This might be safer and even faster than customizing or writing a completely new script (see: xkcd 1205 - Is It Worth the Time?).

You can use metaflac (manpage) for flac files.

$ metaflac --show-sample-rate --show-bps "somefile.flac"

Of course this is not a complete script. You might want to take a look at the Advanced Bash-Scripting Guide.

The following would be a very basic script that deletes all files which return 44100 and 16 to the above command. The directory is given to the script as a parameter (e.g. "Music/All music with 44.1kHz/")


for file in $(find "${1}" -name "*.flac");
    if [ "$(metaflac  --show-sample-rate "$file")" = "44100" ]; then
        if [ "$(metaflac  --show-bps "$file")" = "16" ]; then
            rm -i "$file"

Alternatives to metaflac are: vorbiscomment for ogg, AtomicParsley for mp4/m4a, mid3v2 for mp3 or mediainfo for everything, but they all have different outputs, with mediainfo being overly customizable.

share|improve this answer
metaflac is exactly what I needed, thanks. But when I run the script you suggested (with 96000 and 24 instead of 44100 and 16), it throws the error FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE. What am I doing wrong? – Finwe Oct 28 '13 at 15:50
Remove the doublequotes from "$(find "${1}" -name *.flac)", this should work: $(find "${1}" -name *.flac). With the qoutes all file adresses were concatenated into one long chain (string), not separated as they should have been. – LiveWireBT Oct 28 '13 at 16:02
Perfect. I also wrote a short script to write a list of 24-bit FLAC files (for future reference): #!/bin/bash IFS=$'\n' for file in $(find "${1}" -name *.flac); do if [ "$(metaflac --show-bps "$file")" = "16" ]; then echo "$file">output.txt fi done Sorry for the terrible formatting. – Finwe Oct 28 '13 at 16:29
I think it should be >>output.txt instead or you will only have one file in there. :) – LiveWireBT Oct 28 '13 at 16:37
You probably don't want to look at the ABS, do you? :D Look: you're parsing the output of find... that terrible! It will bite you in the back as soon as a filename contains a newline. – gniourf_gniourf Oct 28 '13 at 20:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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