Summarize File Count (Shell Command)
This shell command summarizes the count of files recursively in a directory by their extensions.
For example:
json 270
js 3
mjs 1
DS_Store 1
Command:
find . -type f -name '*.*' | awk -F. '{print $NF}' | sort | uniq -c | sort -rn | awk '{print $2, $1}'
Explanation:
find . -type f -name '*.*': Find all files in the current directory recursively.awk -F. '{print $NF}': Extract the file extension usingawk.sort: Sort the file extensions. (Required foruniq -cto work correctly)uniq -c: Count the occurrences of each file extension.sort -rn: Sort by count in reverse order.awk '{print $2, $1}': Print the file extension and its count.