Bash: how to build a aggregated list of file extensions with number of occurrences, sorted
Lately I find myself needing to count the number of files in directory, grouped by extension more and more often. So I started brewing on a solution, also googling a bit here and there. Found something, but that one doesn't work if you have directories with a dot in it, and it wasn't very efficient either if you've got lots of directories and files to count.
cd to a directory and execute the command below.
find . -type f | rev | cut -d . -f1 | rev | sort | uniq -ic | sort -rn
Note: it ignores differences in case when comparing extensions. If you don't want that, remove the i parameter from the uniq command.
Files without a extension are seen as unique extension, so you better filter them out first or put a | head -10 or whatever behind it.
Example output:
82845 html
8332 rss
345 png
168 jpg
52 js
14 xml
9 css
3 gif