[Linux] Linux commands for counting folders and files, and linux statistics
# View the number of files in the current directory (excluding files in subdirectories)
Ls-l | grep "^-" | wc-l
# View the number of files in the current directory (including files in sub-Directories) Note: R, representing sub-Directories
Ls-lR | grep "^-" | wc-l
# View the number of folders in the current directory (excluding the directories in the subdirectories). If you want to view the subdirectories, add the R
Ls-l | grep "^ d" | wc-l
# Query the number of all files in the directory with the specified prefix name in the current path
# For example, count the total number of files in all directories starting with "20161124"
Ls-lR 20161124 */| grep "^-" | wc-l
Note the following for each command parameter:
Ls-l
This command outputs the information in the specified directory in a long list (the current directory is not specified), and R indicates the "file" in the subdirectory ", this "file" refers to the general term for directories, links, and device files.
Grep "^ d"Indicates the directory,"^ -"Indicates a file
Wc-l
Indicates the number of rows of output information. Because only common files are left after filtering, and a directory or file corresponds to a row, the number of rows of statistics is the number of directories or files.