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

后端 未结 16 1287
梦谈多话
梦谈多话 2020-11-30 16:00

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

16条回答
  •  死守一世寂寞
    2020-11-30 16:29

    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

提交回复
热议问题