How Linux uses commands to view a few lines of a log file (middle or last lines)
How Linux displays a few lines of a file (in the middle of a few lines)
"One" starts at line No. 3000 and displays 1000 rows. The 3000~3999 line is displayed
Cat FileName | Tail-n +3000 | Head-n 1000
"Two" displays 1000 rows to 3000 rows
Cat filename| Head-n 3000 | Tail-n +1000
* Note the order of the two methods
Decomposition:
Tail-n 1000: Show last 1000 rows
Tail-n + 1000: Starting from 1000 lines, showing 1000 rows later
Head-n 1000: Show front 1000 lines
"Three" with sed command
Sed-n ' 5,10p ' filename so you can only view lines 5th through 10th of the file.
Number of Linux statistics file lines
Syntax: WC [options] File ...
Description: This command counts the number of bytes, words, and lines in a given file. If the file name is not given, it is read from the standard input. The WC also gives the president count of all specified files. The word is the largest string separated by the space character area.
The command options have the following meanings:
-C Count bytes.
-L COUNT the number of rows.
-W counts the number of words.
These options can be used in combination.
The order and number of output columns are not affected by the order and number of options.
Always appear in the following order and at most one column per item.
Number of rows, words, bytes, filenames
If there is no file name in the command line, the file name does not appear in the output.
For example:
$ WC-LCW file1 file2
4 file1
7 File2
Total
Example Analysis:
1. Count the number of JS files in the demo directory:
Find demo/-name "*.js" |wc-l
2. Statistics of all JS file code lines in the demo directory:
Find demo/-name "*.js" |xargs cat|wc-l or Wc-l find ./ -name "*.js"
|tail-n1
3. Statistics of all JS file code lines in the demo directory, Filtered Blank lines:
Find/demo-name "*.js" |xargs cat|grep-v ^$|wc-l
How Linux uses commands to view a few lines of a log file (middle or last lines)