The -name "*.*"
in your find
already excludes any file with no extension since you are looking only for files with at least one .
and then, your grep
is explicitly removing files without extensions:
grep -o -E "\.[^\.]+$"
This will print the extension, but if the file has no extension it will print nothing:
$ echo 'foo.txt' | grep -o -E "\.[^\.]+$"
.txt
$ echo 'foo' | grep -o -E "\.[^\.]+$"
$
If what you want is to count the number of occurrences for each extension or no extension, try this instead:
find . -type f |
awk -F'.' '{
if(NF>2){
ext=tolower($NF)
k["."ext]++ }
else{ k["no extension"]++ }
}
END{ for(i in k){ print i":"k[i] } }'
For example, given this directory:
$ touch file{1..3}.txt file.jpg file.JPG file."weird extension with spaces" file
$ ls
file file1.txt file2.txt file3.txt file.jpg file.JPG
'file.weird extension with spaces'
You get:
$ find . -type f |
> awk -F'.' '{
> if(NF>2){
> ext=tolower($NF)
> k["."ext]++ }
> else{ k["no extension"]++ }
> }
> END{ for(i in k){ print i":"k[i] } }'
no extension:1
.txt:3
.weird extension with spaces:1
.jpg:2
Note that this will consider a hidden file, for example something named .hidden
, as its own extension. That would be counted as one hit for the extension .hidden
. Hidden files with extensions will be counted correctly (i.e. .hidden.txt
will increase the hits for the .txt
extension), but those without extension will not. I don't know how you want to handle that since extensions are largely cosmetic in Linux.
By the way, whether a file is binary or not has nothing to do with whether it has an extension or not.