Photo by Sigmund / Unsplash

Tiny Tool: file types in a directory

tiny tool Oct 21, 2025

I needed to understand directories with far too many files – first stop, were they all equivalent types?

I asked an LLM for help – after an iteration or two, it came up with this, which I've set up with /var/log to work as an example. Change /var/log to . to do the local directory, and you won't need to sudo.

sudo find /var/log -type f -print0 | xargs -0 file --mime-type | cut -d: -f2- | tr -d ' ' | sort | uniq -c | sort -nr

What's it doing?

  • find all files, and output them as a null-delimited list
  • use file on each to pick out the mime type
  • cut the filetype and and trim spaces
  • use sort and uniq to get a -count of how many of each type
  • sort that list putting biggest first.

Tags

James Lyndsay

Getting better at software testing. Singing in Bulgarian. Staying in. Going out. Listening. Talking. Writing. Making.