3

Is there a command(s) to view audio files sorted by length in the command-line?

For example the shortest to longest?

  • @terdon MP3 then, since that's what I have the most of... – TellMeWhy Oct 19 '15 at 9:35
8

If you have ffmpeg installed, try

#!/bin/bash
for file in *.mp3
do
 duration=$(ffprobe "$file" 2>&1 | awk '/Duration/ { print $2 }')
 echo -e $duration"\t"$file
done | sort -n

If you need only the filename, pipe the sort through cut -f 2. Obviously replace *.mp3 with whatever fits your needs.

ffmpeg understands pretty much any common (and not so common) formats.

| improve this answer | |
  • 1
    Can I use for file in *.mp3 && *.ogg && *ogg? or use OR? – TellMeWhy Oct 19 '15 at 9:37
  • 1
    && has a very different meaning in Bash. Simply use *.mp3 *.ogg. Try from the command line echo *.mp3 *.ogg and see how it expands. – Nephente Oct 19 '15 at 9:41
  • Oh right, thnx :) – TellMeWhy Oct 19 '15 at 9:42

Your Answer

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

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