如何在文件夹层次结构中找到所有不同的贪婪文件后缀?

问题描述 投票:-1回答:2

我在这里找到了一个相关问题:

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

但我的情况略有不同。在Ubuntu 14.04 Linux上使用bash,如果我有一堆类似下面的文件:

ls -1 | sort -V
fileA.foo.bar.txt.gz
fileA.foo.foo.txt.gz
fileA.xyz.bar.txt.gz
fileB.foo.bar.txt.gz
fileB.foo.foo.txt.gz
fileB.xyz.bar.txt.gz

我想知道从第一个分隔符中找到的每个扩展名的文件数量(例如示例中的\.)。所以它会是:

2 .foo.bar.txt.gz
2 .foo.foo.txt.gz
2 .xyz.bar.txt.gz

这不是我在上述问题中找到的最佳答案:

find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort | uniq -c | sort -rn
      6 gz

find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort | uniq -c
      6 gz
linux bash ubuntu-14.04
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.