How can I find all file extensions types in a folder or subfolder hierarchy

It work as following:

  • Find all files from current folder
  • Prints extension of files if any
  • Make a unique sorted list
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Or by using awk

find . -type f | awk -F. '!a[$NF]++{print $NF}'

You can also use git as follow

git ls-tree -r HEAD --name-only | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

This is should be better than naive find, because:

  • it excludes untracked (gitignored) files
  • it excludes .git directory which contains usually hundreds/thousands of files and hence slows down the search

If you still haven’t upgraded to Linux from Shitdows, then the powershell command looks like this (powershell not cmd (Command promt)):

dir -recurse | select-object extension -unique

Skriv et svar