Linux 如何计算文件夹中的所有文件、其子文件夹和所有 . 计数不应包括文件夹计数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9769434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:15:43  来源:igfitidea点击:

How to count all files inside a folder, its subfolder and all . The count should not include folder count

linuxcommand-line

提问by Peter

How to count all files inside a folder, its subfolder and all . The count should not include folder count.

如何计算文件夹中的所有文件、其子文件夹和所有 . 计数不应包括文件夹计数。

I want to do it in MAC

我想在 MAC 上做

采纳答案by Jeff Foster

find . -type f | wc -lwill recursively list all the files (-type frestricts to only files) in the current directory (replace .with your path). The output of this is piped into wc -lwhich will count the number of lines.

find . -type f | wc -l将递归列出-type f当前目录中的所有文件(仅限于文件)(替换.为您的路径)。它的输出通过管道输送到wc -l其中将计算行数。

回答by perreal

Find all files under myfolderand count them using wc. This works on linux:

查找所有文件myfolder并使用wc. 这适用于Linux:

find myfolder -type f | wc -l

find myfolder -type f | wc -l