Getting all extensions for a directory: easy. Getting file counts for a particular extension: easy.
But getting all file extensions and their respective file counts is alluding me.
eg.
+ dir
+ abc.txt
+ def.txt
+ abc.pdf
* def.pov
should return something like:
.txt 2
.pdf 1
.pov 1
The aim of this exercise is that I want to find out which file extension is popular in a certain directory.
Thanks in advance
Here is the explication:
find only file, not directory
filter file with extension
delete path and file name, save only extension
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: