Shell script to find all types of files in a directory with their count

find . -type f -name '*.*' -exec sh -c 'echo ${0##*.}' {} \; | sort | uniq -c | sort -nr

The echo ${0##*.} gives you the extension of the file. We pipe the output to sort and then count the unique lines with uniq.

Some additions:

  • Since the output of uniq is not sorted according to the number of occurrences, you'll have to pipe again into a numeric sort (-nr) if you want it sorted.
  • If you want to search your current directory only, add -maxdepth 1 to your find command.
  • Pipe into awk '{print $2, $1}' to show the count after the extensions.