I doubt that there's an existing findmp3
tool. Following the unix philosophy, it can be built from find
to find .mp3
files, another tool to report the length of each file that find
finds, and some shell/text processing glue.
SoX is a commonly available utility to work with sound files (sox is to sound what sed or awk are to text files). The command soxi
displays information about a sound file. In particular, soxi -D
prints the duration in seconds.
For each .mp3
file, the snippet below calls soxi
and parses its output. If the duration is within the desired range, the sh
call returns a success status, so the -print
action is executed to print the file name.
find /music/mp3/ebm -type f -name .mp3 -exec sh -c '
d=$(soxi -D "$0")
d=${d%.*} # truncate to an integer number of seconds
[ $((d >= 3*60 && d < 3*60+15)) -eq 1 ]
' {} \; -print
In bash, ksh93 or zsh, you can use recursive globbing instead of find
. In ksh, run set -o globstar
first. In bash, run shopt -s globstar
first. Note that in bash (but not in ksh or zsh), **/
recurses through symbolic links to directories.
for f in /music/mp3/ebm/**/*.mp3; do
d=$(soxi -D "$0")
d=${d%.*} # truncate to an integer number of seconds (needed in bash only, ksh93 and zsh understand floating point numbers)
if ((d >= 3*60 && d < 3*60+15)); then
echo "$f"
fi
done