> ## Content Index
> Fetch the complete content index at: https://www.workroom-productions.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Tiny Tool: file types in a directory
- URL: https://www.workroom-productions.com/file-types-in-a-directory/
- Published: 2025-10-21T15:21:49.000Z
- Updated: 2025-10-21T15:21:49.000Z
- Description: A one-liner to see the most-common file types in a directory
- Author: James Lyndsay
- Tags: tiny tool

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 `tr`im spaces
- use `sort` and `uniq` to get a `-c`ount of how many of each type
- sort that list putting biggest first.