How to count the number of files in a directory and the commands for the total number of lines under Linux
The total number of files that know the specified suffix name command:
Find. -name "*.cpp" | Wc-l find
.-maxdepth 1-name "*.sh" |wc-l
Know the total number of lines of code in one directory and the number of individual file rows:
Find. -name "*.h" | Xargs wc-l find
.-name "*.C" | xargs grep "^." | wc-l//Excluding blank lines wc-l ' find.-name ' *.c '//Note the Find
content is ~ below the character No, it's wrapped.
Number of files in Linux statistics folder
The first method:
Ls-l|grep "^-" |wc-l
Ls-l: Long list output The file information in this directory (note the file here, different from the general file, may be directories, links, device files, etc.). If the Ls-lr|grep "^-" |wc-l can be counted together with the files in the subdirectory.
grep ^-: This will be a long list of output information filter part, only the general file, if only keep the directory is ^d.
Wc-l: Statistics output The number of lines of information, because has filtered only the general file, so the statistical result is the number of general file information, and because a line of information corresponding to a file, so that is the number of files.
The second method:
Find./-type F|wc-l
Because the default find will go to the subdirectory lookup, if you only want to find the files in the current directory, use finding./-maxdepth 1-type f|wc-l.
It should be explained that the second method is much faster than the first method, especially when subdirectories are counted.
the number of statistical directories and their subdirectory files under Linux system
To view the number of files in a directory:
Ls-l |grep "^-" |wc-l find
./company-type F | wc-l
View the number of files in a directory, including subdirectories:
Ls-lr|grep "^-" |wc-l
View the number of directories under a folder, including those in subdirectories:
Ls-lr|grep "^d" |wc-l