Get total length of all media files in the current directory
February 14, 2016

Have you ever needed to find the total length of all media files in the current directory? If so, this tip is for you.

This command requires python to be installed. It is by default on most linux distros. It also requires the command soxi, which on Ubuntu, is contained in the package sox. You can install it by typing sudo apt-get install sox into the terminal.

Here is the command:

soxi -D * | python -c "import sys; print sum(float(l) for l in sys.stdin)"

Explanation:

  • soxi -D * Finds the duration of all files in the current folder and prints them one per line.
  • python -c "import sys; print sum(float(l) for l in sys.stdin)" Adds up the numbers on all the lines outputted by soxi.

I hope you find this useful!

Patrick G
Patrick G
I like to write code. I love open source software. I like to self-host stuff.