Head and tail commands for linux commands, and tail commands
-
- Head
- Tail
- Example of combined head and tail usage
Head syntax
head [-n -k ]... [FILE]...
Example
- The first 10 rows are displayed by default.
head /etc/passwd
- Displays the first k rows.
Head-k/etc/passwdhead-n k/etc/passwd (note the difference between head-n + k/etc/passwd)
- All contents except the last k rows are displayed.
head -n -k /etc/passwd
Tail syntax
tail [-n -k ]... [FILE]...
Example
- By default, the last 10 rows are displayed.
tail /etc/passwd
- Displays the last k rows.
Tail-k/etc/passwdtail-n k/etc/passwd (note the difference with the following) tail-n-k/etc/passwd
- The output starts from the first k rows.
tail -n +k /etc/passwd
Example of combined head and tail usage
// The first 20 rows are displayed, excluding the last 3 rows of head-n-3/etc/passwd | tail-n + 11, however, starting from row 3, head-n 20/etc/passwd | tail-n + 11 // displays all rows except the last three rows, however, only the last 10 rows of head-n-3/etc/passwd are displayed. | tail-n 10 // the last 10 rows of head-n 20/etc/passwd are displayed. | tail -n 10 // The value is displayed starting from row 11th, however, only the first 10 rows of tail-n + 11/etc/passwd | head-n 10 // are displayed starting from row 11th, excluding the last three rows of tail-n + 11/etc/passwd | head-n-3 // display the first 10 rows of tail-n 13/etc/passwd in the last 13 rows | head-n 10 // display the first 10 rows except the last three rows in the last 13 rows: tail-n 13/etc/passwd | head-n-3
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.