Linux provides ready-made commands to count the number of bytes, rows, and other information in a file. The WC command can easily resolve this issue.
The WC command, which can be used to count bytes (byte), Word (word), line (newline), etc. in each file, and if multiple files are given, the total number of rows is also calculated. The word (word) refers to a sequence of characters separated by a space.
How to use:
WC [option] ... [File] ...
The common options [option] are:
-C,--bytes output byte count
-M,--chars output character count
-L,--lines output line number
-w,--words Output Word Count
For example:
WC-LCW Test.txt
Output Result:
577 Test.txt
Among them, 13 is lines,68 for words,577 for bytes.
It is important to note that the order and number of output columns are not affected by the order and number of options, and are always displayed in the order of the number of rows, words, bytes, filenames, and a maximum of one column per item.
Let me give you an example:
WC-LCW a.txt B.txt
The output is:
101 909 4846 A.txt
171 912 B.txt
5758 Total
Where the last line is the sum total of the statistics calculated in the previous file.
In addition, if it is:
WC-LW a.txt B.txt
The output is:
101 909 A.txt
171 B.txt
Total
However, if [option] is the default, it is the same as-LCW
For example: WC a.txt b.txt
The output is:
101 909 4846 A.txt
171 912 B.txt
5758 Total
[Linux] Linux statistics file lines