Head and tail commands for linux commands, and tail commands

Source: Internet
Author: User

Head and tail commands for linux commands, and tail commands

    • Head
      • Syntax
      • Example
    • Tail
      • Syntax
      • Example
    • 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.

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.