Get all extensions and their respective file count in a directory
/var/cache$ sudo find ./ -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n
1 .6
1 .cache
1 .noconf
1 .php
1 .sl
2 .bin
2 .el
2 .tdb
4 .baseA
4 .baseB
4 .dat
4 .DB
27 .db
221 .deb
Here is the explication:
find ./ -type f
find only file, not directory
grep -E ".*\.[a-zA-Z0-9]*$"
filter file with extension
sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/'
delete path and file name, save only extension
sort | uniq -c | sort -n
sort, uniq and sort
Since you're using Linux (gnu grep), this is a good time to use Perl REs (PCRE) -P
and grep's -o
option. Taking @bindbn's answer as a great candidate:
find . -type f | grep -Po '\.([\w\d])*$' | sort | uniq -c | sort -n