How can I find all of the distinct file extensions in a folder hierarchy?

GloryFish picture GloryFish · Dec 3, 2009 · Viewed 117.8k times · Source

On a Linux machine I would like to traverse a folder hierarchy and get a list of all of the distinct file extensions within it.

What would be the best way to achieve this from a shell?

Answer

Ivan Nevostruev picture Ivan Nevostruev · Dec 3, 2009

Try this (not sure if it's the best way, but it works):

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

It work as following:

  • Find all files from current folder
  • Prints extension of files if any
  • Make a unique sorted list