Celeb Glow
news | March 21, 2026

How can I delete files based on (flac) metadata?

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?

1 Answer

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"
44100
16

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. flac-44100-removal.sh "Music/All music with 44.1kHz/")

#!/bin/bash
IFS=$'\n'
for file in $(find "${1}" -name "*.flac");
do if [ "$(metaflac --show-sample-rate "$file")" = "44100" ]; then if [ "$(metaflac --show-bps "$file")" = "16" ]; then rm -i "$file" fi fi
done

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.

7

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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