本文翻译自:Count number of files within a directory in Linux? [closed]
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
命令吗?
#1楼
参考:https://stackoom.com/question/1pFOO/计算Linux目录中文件的数量-关闭
#2楼
this is one: 这是一:
ls -l . | egrep -c '^-'
Note: 注意:
ls -1 | wc -l
Which means: ls:
list files in dir 这意味着: ls:
列出dir中的文件
-1:
(that's a ONE) only one entry per line. -1:
即ONE)每行只有一个条目。 Change it to -1a if you want hidden files too 如果您也想要隐藏文件,请将其更改为-1a
| :
| :
pipe output onto... | :
管道输出到...
wc:
"wordcount" wc:
“ wordcount”
-l:
count l
ines. -l:
计数l
分级表。