This Bourne shell one-liner, when used inside a directory containing only music files, will output their total length in seconds with a very high degree of precision:
LENGTH=0; for file in *; do LENGTH="$LENGTH+$(ffprobe -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" 2>/dev/null)"; done; echo "$LENGTH" | bc
Modified to only output the length of .mp3 files (and thus avoid breaking on the innocuous .docx sitting within our music directory), it would look like this:
LENGTH=0; for file in *.mp3; do if [ -f "$file" ]; then LENGTH="$LENGTH+$(ffprobe -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" 2>/dev/null)"; fi; done; echo "$LENGTH" | bc
And if, for example, we wanted to output the total length of audio with only several different file extensions, we can do that as well by adding a second wildcard, still avoiding the dreadful, scary .docx:
LENGTH=0; for file in *.mp3 *.ogg; do if [ -f "$file" ]; then LENGTH="$LENGTH+$(ffprobe -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file" 2>/dev/null)"; fi; done; echo "$LENGTH" | bc
Naturally, ffmpeg has to be installed to use either of these.
awk
is available on all Unix/Linux platforms as part of the std install. Good luck. – Antidisestablishmentarianism