The head command is used to view the content at the beginning of a file. There is a commonly used parameter -n to display the number of lines. The default is 10, that is, 10 lines. If multiple file names are provided, the data in each file begins with its file name.
The command format
Head [parameter]... [file]...
Command function
Head is used to display the beginning of the file to standard output. The default head command prints the first 10 lines of the corresponding file.
The command parameter
- -q Hides file names. This parameter is valid when multiple file names are used
- -v Displays the file name
- -c N Displays the contents of N bytes from the beginning
- -n n Displays n lines from the beginning
Displays the first 10 lines of the file
> head -n 10 1.txt
Copy the code
Displays the first 10 bytes of the file
> head -c 10 1.txt
Copy the code
Displays the contents from the file header to the NTH character
N= 2; N= 2; N= 2;Copy the code
View multiple files at the same time
TXT ==> 1. TXT <== VVV CCC 123 9090 ASD 123 123 444 99 ==> 2. TXT <== starter rumenzCopy the code
View multiple files at the same time without displaying the file names
> head-n 5-q 1.txt 2. TXT head-n 5-q 1.txt 2. TXT VVV CCC 123 9090 ASD 123 123 444 99Copy the code
Displays the contents from the beginning to the last NTH line of the file
> head -n -5 1.txt
Copy the code
Head Print line between lines M and N of output file (M>N)
Output the contents of lines 10(N=10) through 20(M=20) of the file
> head -n 20 1.txt | tail -10
Copy the code
Output the last three files in the current directory
> ls -t | head -n 3
Copy the code
Original link :rumenz.com/rumenbiji/l… Wechat official account: entry station