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

后端 未结 16 1255
梦谈多话
梦谈多话 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:36

    The accepted answer uses REGEX and you cannot create an alias command with REGEX, you have to put it into a shell script, I'm using Amazon Linux 2 and did the following:

    1. I put the accepted answer code into a file using :

      sudo vim find.sh

    add this code:

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

    save the file by typing: :wq!

    1. sudo vim ~/.bash_profile

    2. alias getext=". /path/to/your/find.sh"

    3. :wq!

    4. . ~/.bash_profile

提交回复
热议问题