-
- Head
- Tail
- Examples of how head and tail combinations are used
Head syntax
head [-n -k ]... [FILE]...
Sample Example
- The default is to display the first 10 rows.
head /etc/passwd
- Displays the top K lines before the start.
-k-n k /etc/passwd(注意和以下的有--n+k /etc/passwd
- All remaining content is displayed except for the last K line.
-n-k /etc/passwd
Tail syntax
tail [-n -k ]... [FILE]...
Sample Example
- The default is to display the end 10 rows.
tail /etc/passwd
- Displays the end of the K line.
-k-n k /etc/passwd(注意和以下的有+-n-k /etc/passwd
- Start at the beginning of line K to output.
-n+k /etc/passwd
Examples of how head and tail combinations are used
//Starts from line 11th, but does not contain the last 3 rowsHead- N -3/etc/passwd|Tail- N + One//Display the first 20 lines, but start at line 11thHead- N -/etc/passwd|Tail- N + One //Display all rows except the last 3 lines, but only the last 10 rowsHead- N -3/etc/passwd|Tail- N Ten //Display the last 10 lines in the first 20 rowsHead- N -/etc/passwd|Tail- N Ten //start from line 11th, but show only the first 10 rowsTail- N + One/etc/passwd|Head- N Ten //Starts from line 11th, but does not contain the last 3 rowsTail- N + One/etc/passwd|Head- N -3//Display the first 10 lines in the last 13 rowsTail- N -/etc/passwd|Head- N Ten //Show the top 10 rows in the last 13 rows except the 3 lines at the endTail- N -/etc/passwd|Head- N -3
The head and tail commands of the Linux command are explained in detail