I don't know who would find this useful, but at work today I was reminded that I used to run this command when I did digital archives work and wanted a rough count of what file types are in a directory

find . -type f -exec file {} \; | cut -d ':' -f 2 | cut -d ',' -f1 | sort | uniq -c | sort -n -k 1

I posted and deleted this a couple of times attempting to format the text around the command-line string, but I guess I don't know what kind of mark up is supported here.


@andrewjbtw I'm impressed you know how to use find like that--I always resort to using xargs because I can never remember.

That little cut, sort and uniq trick is so useful to compose in situations where you've got a pipeline of things to count.

I feel like this command needs a memorable alias like ftypes, or maybe something magical ✨

@edsu for whatever reason, I've always found xargs hard to grasp. When I use it I often end up running another bash command with 'bash -c' At work I use xargs to parallelize things if parallel isn't installed.

I've gotten comfortable with 'find ... -exec' for simple things after the exec. In this case, the pipe into cut won't handle filenames with colons properly for the outcome I want and I'd probably use something with xargs to deal with that if needed.

Sign in to participate in the conversation

A Fediverse instance for people interested in cooperative and collective projects.