Linux counts the number of files in the folder

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, -loptions are listed in the details, -Rthe option is recursive; then the second step grepregular expression, the result of the first step through the pipeline |as a second step input, then, by grepThe conditions are selected to meet the conditions; the third step is to wccount the quantity.

Guess you like

Origin blog.csdn.net/Gou_Hailong/article/details/114920199