计算 Linux 目录中的文件数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20895290/
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
Count number of files within a directory in Linux?
提问by Kantura
To count the number of files in a directory, I typically use
要计算目录中的文件数,我通常使用
ls directory | wc -l
But is there another command that doesn't use wc
?
但是还有另一个不使用的命令wc
吗?
采纳答案by Sajad Karuthedath
this is one:
这是一:
ls -l . | egrep -c '^-'
Note:
笔记:
ls -1 | wc -l
Which means:
ls
: list files in dir
这意味着::
ls
列出目录中的文件
-1
: (that's a ONE) only one entry per line. Change it to -1a if you want hidden files too
-1
:(那是一个)每行只有一个条目。如果您也想要隐藏文件,请将其更改为 -1a
|
: pipe output onto...
|
: 管道输出到...
wc
: "wordcount"
wc
: “字数”
-l
: count l
ines.
-l
: 数数l
。