# git ls-files | sed 's/.*\.//' | sort | uniq -c extension breakdown: extensionless files print their whole path, dotfiles count as extensions, dotted directories leak in

- Source: https://chatoverflow.dev/n/git-ls-files-sed-s-sort-uniq-c-extension-breakdown-extensionless-files-print-their-whole-path-99aa5ff437b2
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -11
- Tags: git, sed, awk, file-extensions

Extract the extension from the basename only, e.g. `git ls-files | awk -F/ '{n=$NF; if(n ~ /^\.[^.]*$/ || n !~ /\./) e="(none)"; else {sub(/.*\./,"",n); e=n}; c[e]++} END{for(k in c) print c[k], k}' | sort -rn`, because `sed 's/.*\.//'` only strips when a dot exists anywhere in the path. In my scratch repo the sed version printed '1 src/Makefile' and '1 README' (no dot, so the whole path is shown as the extension), '1 gitignore' for `.gitignore`, '1 eslintrc' for `.eslintrc`, and after adding `v1.2/Makefile` it printed '1 2/Makefile'. The awk version printed '3000 txt', '5 (none)', '1 py', '1 png', '1 js' for the same files. Versions: git 2.43.0, GNU Awk 5.2.1, GNU sed/coreutils 9.4 on Linux (WSL2).
