Long time lurker, first time questioneer!

I can't find the following: I would like to make a textfile which is filled with filenames including the ones in subdir's, their path and and metadata (especially video resolution). All that from console.

I couldn`t find something similar, only something called mediainfo which gets close, but only works for 1 file as far as I see.

Could someone point me in the right direction? Thanks for your time! Cheers

And please keep your hands of my question.


In general, the way one takes a 1-argument command (mediainfo foo) and applies it to a bunch of files, is with find and xargs. See man find;man xargs.

I'm using the NUL-terminated options (-print0 and -0) because you did not say no filename had spaces.

find . -type f -print0 | xargs -0 -n 1 mediainfo
  • Not sure on double negative not and no. But I would assume most people have spaces in their filenames. – WinEunuuchs2Unix Aug 24 '18 at 21:52
  • It works with filenames, even the ones with spaces in it, and its writing correctly to a text file with "<". Got alot of "extra information" but its going in the right direction. Thanks! – Zwolse Aug 24 '18 at 22:06
  • 1
    Or use -exec mediainfo {} \; There's no point in passing to xargs. And yes -exec will handle filenames with spaces – Sergiy Kolodyazhnyy Aug 25 '18 at 0:46

mediainfo is an excellent choice for obtaining this information. I would use a script to ensure I was getting the results I wanted on a single file and then iterate it across the scope desired. Here's an example I called 1linenfo.sh and placed in my ~/bin directory:

As with all scripts you plan on executing you'll have to change the permissions to executable. in this specific case that would be chmod +x ~/bin/1linenfo.sh

#! /bin/bash
pfx=$(mediainfo --Inform="General;%CompleteName%" "$1")
sfx=$(mediainfo --Inform="Video;%Width%x%Height%" "$1")
Title="$pfx $sfx" #build desired line of output
echo "$Title" #output

The above includes the information that you want but you can easily add more. For more detailed output choices check the output of mediainfo --Info-Parameters

You can easily utilize find to iterate this across your desired scope.

find . -type f -exec bash -c '1linenfo.sh "{}"' \;

If you need to redirect the output to a file you can do something like this:

find . -type f -exec bash -c '1linenfo.sh "{}"' \;>report.txt

If anything about this answer is unclear, drop me a comment and I'll do me best to clarify.

  • 1
    If the script is in ~/bin and OP already sourced ~/.bashrc then there's no need for bash -c part, the -exec flag will search directories in PATH and find the script just fine. And of course it needs executable permission, so may wanna mention chmod +x on the script – Sergiy Kolodyazhnyy Aug 25 '18 at 15:49

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.