CodeFaster

CodeFaster

unix 1 liner to get total minutes of audio

Tyler Adams's avatar
Tyler Adams
Jul 25, 2023
∙ Paid
3
2
Share

I’m upscaling some audio and the website asked me to state how many minutes I’d need:

In a code block, the one-liner looks like this:

Thanks for reading CodeFaster! Subscribe for free to receive new posts and support my work.

find | grep mp3$ | xargs -L 1 mp3-minutes | math-sum

This one-liner does the following:

  1. The find command lists all the files and directories in the current location.

  2. The output of find is then piped to grep mp3$ which filters and retains only the lines ending with mp3.

  3. The filtered list of mp3 files is then piped to xargs -L 1 mp3-minutes which executes the mp3-minutes command on each mp3 file to find the duration in minutes of each file.

  4. The resulting list of durations is then piped to math-sum which sums up all the durations to give a total.

Lets break down each stage with partial outputs.

  1. The find command

It lists all files and directories recursively in a directory. The output includes both file and directory names.

Partial Output:

.
./3_Vayikra
./3_Vayikra/7_Kedoshim
./3…

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Tyler Adams
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture