ls -l | wc -l #统计当前文件夹中文件数量(包括子文件夹和文件)
ls -l | grep '^-' | wc -l #统计当前文件夹中文件数量(只包括文件)
ls -l | grep '^d' | wc -l #统计当前文件夹下子文件夹数量
ls -lR | grep '^-' | wc -l #统计当前文件夹下文件数量(包括子文件夹下的文件)
ls -lR | grep '^d' | wc -l #统计当前文件夹下文件夹数量(包括子文件夹下的文件夹)
ls -lR | wc -l #统计当前文件夹中文件数量(包括子文件夹下的文件夹和文件)
In fact, the command is very simple, look decomposition, the first step ls
, -l
options are listed in the details, -R
the option is recursive; then the second step grep
regular expression, the result of the first step through the pipeline |
as a second step input, then, by grep
The conditions are selected to meet the conditions; the third step is to wc
count the quantity.