Count the total number of rows in a directory for all normal files
Scenario One: Find. -type f-name "*.C"-exec cat {} \; | Grep-v ' ^$ ' | Wc-l
Explanation: Find. -type f-name "*.c" finds all files ending with. C in the current directory, and can be directly useful if you do not consider file types. -type F can be. -exec Cat {} \; is to be found in the file using the cat command output; Grep-v ' ^$ ' is not a blank line of content to be counted, if the blank line does not count, it is equivalent to a filter. Wc-l the number of lines of code that the statistic outputs. If you do not need to filter the empty line, you can save Grep-v ' ^$ '
Scenario Two: Find. -type f-exec wc-l {} \; | awk ' {sum+=$1}end{print sum} '
Explanation: Find command with Scheme one. -exec wc-l refers to the number of rows in which the file will be found, which, if output, outputs a similar
Main.c
Head1.h
head1.c
So it's also important to use awk to add the first column, and by Sum+=$1, it's obvious that it's easier to understand the meaning of awk. However, this method does not filter for empty rows.
Scenario Three: Find. -type F | Xargs wc-l
Explanation: The difference between using Xargs and scenario two is that when a matching file is processed using the-EXEC option of the Find command, the Find command passes all matching files to exec execution. However, some systems have limits on the length of commands that can be passed to exec, so that an overflow error occurs several minutes after the find command has been run. The error message is usually either "too long" or "parameter column overflow." This is the use of the Xargs command, especially with the Find command.
The Find command passes the matching file to the Xargs command, and the Xargs command gets only a portion of the file at a time instead of all, unlike the-exec option. This allows it to process the first part of the file, then the next batch, and so on.
For scenario three, the system displays the number of rows per file, and then displays the Total row count:
/main.c
8./abc.c
8./folder/main.c
8./folder/shaoning/test.c
38 Total Dosage