Home >Operation and Maintenance >Linux Operation and Maintenance >How to read the last few lines in cat in linux
In Linux, you can use the cat command with the tail command to view the last few lines of the file; the cat command is used to connect files and print to the standard output device, and the tail command can be used to view the contents of the file. When tail When the parameter of the command is set to "-n", the contents of the specified lines at the end of the file can be displayed. The syntax is "cat specified file | tail -n displays the number of the last few lines".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
The cat (full English spelling: concatenate) command is used to connect files and print to the standard output device.
Syntax format
cat [-AbeEnstTuv] [--help] [--version] fileName
Parameter description:
-n or --number: Number all output lines starting from 1 .
-b or --number-nonblank: Similar to -n, except that blank lines are not numbered.
-s or --squeeze-blank: When encountering more than two consecutive blank lines, replace them with one blank line.
-v or --show-nonprinting: Use the ^ and M- symbols except LFD and TAB.
-E or --show-ends : Show $ at the end of each line.
-T or --show-tabs: Display TAB characters as ^I.
-A, --show-all: Equivalent to -vET.
-e: Equivalent to the "-vE" option;
-t: Equivalent to the "-vT" option;
tail command can be used to view the contents of the file,
Command format:
tail [参数] [文件]
Parameters:
-f Loop reading
-q Do not display processing information
-v Display detailed processing information
-cc8f01a3f8889dcf657849dd45bc0fc4c The number of bytes displayed
##-ne1bb43da1dc495f3a2319be5fe7b6df5 Display the last n lines of the file
The example is as follows
Combine the three commands to view line x to line Y of the file. Syntax format 1: Starting from line X, display line Y. That is, display the Y rowcat filename | tail -n +X | head -n YExample: Display rows 1000 to 3000
cat requirements.txt | tail -n +3000 | head -n 1000*Note the order of the two methodsDecomposition: tail -n 1000: Display the last 1000 lines
Linux video tutorial
The above is the detailed content of How to read the last few lines in cat in linux. For more information, please follow other related articles on the PHP Chinese website!