且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查找和计算与给定字符串匹配的文件数?

更新时间:2022-11-12 20:27:50

您可以使用

find / -type f -name 'foo*' | wc -l




  • 使用单引号防止外壳扩展

  • 使用型f 仅包含文件(不包括链接或目录)。

  • wc -l 表示字数,仅行数。由于查找每行将列出一个文件,因此将返回找到的文件数。

    • Use the single-quotes to prevent the shell from expanding the asterisk.
    • Use -type f to include only files (not links or directories).
    • wc -l means "word count, lines only." Since find will list one file per line, this returns the number of files it found.