Tiny Tool: file types in a directory
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?
-
findall files, and output them as a null-delimited list - use
fileon each to pick out the mime type cutthe filetype and andtrim spaces- use
sortanduniqto get a-count of how many of each type - sort that list putting biggest first.
Comments
Sign in or become a Workroom Productions member to read and leave comments.