Count the number of files in a folder
Ls-l |grep "^-" |wc-l
Count the number of directories under a folder
Ls-l |grep "^d" |wc-l
The number of files under the statistics folder, including subfolders
Ls-lr|grep "^-" |wc-l
All JS files in the Statistics/home/han directory (including subdirectories) are:
Ls-lr/home/han|grep js|wc-l or Ls-l "/home/han" |grep "JS" |wc-l
The number of directories under the statistics folder, including the sub-folders
Ls-lr|grep "^d" |wc-l
Description
Ls-lr
Long list output file information in this directory (R for subdirectories note the files here, different from the general files, may be directories, links, device files, etc.)
grep "^-"
In this case, the long list output information is filtered, only the general files are preserved, if only the directory is ^d
Wc-l
Statistics output information of the number of rows, because it has been filtered to only the general file, so the statistical results are general file information line number, and because one line of information corresponding to a file, so that is the number of files.
======================================
If you view only folders
Ls-d can only display one.
Find-typed can see sub-folders
Ls-lf |grep/or ls-l |grep ' ^d ' only look at folders under current directory, not including down folders
Linux statistics the number of files and folders under a folder