I'm looking for a simple shell command that analyses all flac files in a folder and deletes all files that have a lower bitrate than 950kbps. Now I have to fire up Clementine, browse to the folder, sort the files and delete manually. That's all I use Clementine for, which is overkill I think. Thanks a lot
1 Answers
To my knowledge there is no simple command to carry out such an operation. However a small script that browses the files in a folder can do the trick.
First thing first, we need a command line utility to get the bit rate of the files. I use mediainfo (mediainfo package on Debian). Other utilities can also do the job very well. Once installed, the following script lists all the FLAC files in the folder with a bit rate lower than 950 kbps.
#!/usr/bin/env sh
for flacfile in .flac; do
[ $(mediainfo "$flacfile" | grep 'Bit rate' | grep -oi '[0-9].[0-9]' | sed 's/\s//g') -lt 950 ] && echo "$flacfile"
done
If it suits you, just replace the echo command by the rm command to proceed the file deletion:
#!/usr/bin/env sh
for flacfile in .flac; do
[ $(mediainfo "$flacfile" | grep 'Bit rate' | grep -oi '[0-9].[0-9]' | sed 's/\s//g') -lt 950 ] && rm "$flacfile"
done
Explanation
- the
forloops browses all the.flacfiles in the directory; mediainfodisplays all the information about the FLAC file and gives it to the firstgrepcommand;- the first
grepselects the bit rate line and gives it to the secondgrep; - the second
grepselects in this line only the numbers. The.in[0-9].[0-9]*deals with space thousand separator (in1␣050for example); sedremoves the space thousand separator if needed;- finally
[ ... -lt 950 ]checks if the bit rate is less than 950 kbps and if it is true thermcommand removes the file.
-
That is absolutely spectacular, thank you so much :D That is exactly what I needed. Thank you very much :) – Robert van Wingen May 19 '20 at 18:07