Count files by extension without breaking on spaces
Build a paste-ready command, then review its compatibility and effects before running it.
find <path> -type f -printf '%f\n' | awk -F. 'NF==1 {ext="[none]"} NF>1 {ext=tolower($NF)} {count[ext]++} END {for (ext in count) print count[ext], ext}' | sort -nrComplete required fields to copy the generated command.
read-onlyno known side effects Compatibility
LinuxVerified for Linux using bash, zsh syntax.
Operational knowledgereview due 2027-01-19
Requirementsfindfind must be installed and available on PATH.
Version supportfind Current supported releasesVerified for linux using bash, zsh syntax; consult compatibility notes for platform-specific differences.
Expected signals184 tsRepresentative successful output; values vary with the selected target and system state.
Known errorsfind: command not foundfind is missing or is not available on PATH.
Verifyfind {{path}} -type f -printf '%f\n' | awk -F. 'NF==1 {ext="[none]"} NF>1 {ext=tolower($NF)} {count[ext]++} END {for (ext in count) print count[ext], ext}' | sort -nrThe output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01findCommandRuns the find stage of this one-liner.
02<path>ParameterA value supplied in the Fill parameters section.
03-typeOptionConfigures find with the -type option.
04fArgumentPasses f to find.
05-printfOptionConfigures find with the -printf option.
06'%f\n'ArgumentPasses '%f\n' to find.
07|PipelinePasses the output on the left to the command on the right.
08awkCommandRuns the awk stage of this one-liner.
09-F.OptionConfigures awk with the -F. option.
10'NF==1 {ext="[none]"} NF>1 {ext=tolower($NF)} {count[ext]++} END {for (ext in count) print count[ext], ext}'ArgumentPasses 'NF==1 {ext="[none]"} NF>1 {ext=tolower($NF)} {count[ext]++} END {for (ext in count) print count[ext], ext}' to awk.
11|PipelinePasses the output on the left to the command on the right.
12sortCommandRuns the sort stage of this one-liner.
13-nrOptionConfigures sort with the -nr option.
This advanced community-curated one-liner combines several stages. Review every option and placeholder before running it.
Example input
find ./project -type f -printf '%f\n' | awk -F. 'NF==1 {ext="[none]"} NF>1 {ext=tolower($NF)} {count[ext]++} END {for (ext in count) print count[ext], ext}' | sort -nr
Example output
184 ts
62 json
31 md
4 [none]
Illustrative output — exact values vary by system and data.
Official sources