Photo by Sigmund / Unsplash

Tiny Tool: file types in a directory

tiny tool Oct 21, 2025 (Oct 21, 2025) Loading...

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.

Member reactions

Reactions are loading...

Sign in to leave reactions on posts

Tags

Comments

Sign in or become a Workroom Productions member to read and leave comments.

James Lyndsay

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

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.