Count The Different Types Of Files In A Directory Tree In Linux

Use the following command to print a sorted list of the number of different types of files within the current directory.

find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort | uniq -c | sort -n 

See a breakdown of what this command does on explainshell.com.

Alternatively, this command will do the same.

find . -name '*.?*' -type f | rev | cut -d. -f1 | rev  | tr '[:upper:]' '[:lower:]' | sort | uniq --count | sort -rn

See a breakdown of what this command does on explainshell.com.

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
1 + 13 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.