You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like '\d+\s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po '\d+\s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po '\d+\s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps