The head and tail commands of the Linux command are explained in detail

Source: Internet
Author: User

      • Head
        • Grammar
        • Sample Example
      • Tail
        • Grammar
        • Sample Example
      • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.