Text Processing command series--head and tail

Source: Internet
Author: User

Head: View the contents of the file, the first 10 lines of content are displayed by default.

Tail: View the contents of a file, which shows the following 10 lines by default.


Head and tail if you want to display the contents of the specified number of rows, you can use the-n option.

Option Description: Head-n Number: Displays the contents of the previous number line. Head-c number-bytes: Displays the contents of the preceding number of bytes. You can use units such as K. such as Head-c 5k Display the contents of the top 5 K. Head-n-number: Displays all rows except for the following number lines.
Tail-n Number: Displays the contents of the following number rows. Tail-c number-bytes: Displays the contents of the following number of bytes. Tail-n +number: Displays the contents of all rows starting from the number line. TAIL-F FileName: Constant monitoring of changes in the content of a file, often used to view log files. Tail-f FileName: The function is the same as tail-f, but when a monitored file is moved, tail-f retries.


Example:

[[email protected] ~]# cat -n /etc/services | head      1# /etc/services:     2#  $Id:  services,v 1.48 2009/11/ 11 14:32:31 ovasik exp $     3#     4#  network services, internet style     5# iana services  version: last updated 2009-11-10     6#      7# note that it is presently the policy of iana to  assign a single well-known     8# port number for  both TCP and UDP; hence, most entries here have two  ENTRIES     9# EVEN IF THE PROTOCOL DOESN ' T support  udp operations.    10# updated from rfc 1700,  "Assigned Numbers"   ( october 1994).   not all ports[[email protected] ~]#
[[email protected] ~]# cat -n /etc/services | tail 10765nimgtw           48003/udp                # Nimbus Gateway 107663gpp-cbsp        48049/tcp                # 3gpp cell broadcast service protocol 10767isnetserv        48128/tcp                # image systems network services 10768isnetserv        48128/udp                # Image Systems Network Services 10769blp5             48129/tcp                # Bloomberg locator 10770blp5             48129/udp                # Bloomberg locator 10771com-bardac-dw   48556/tcp                # com-bardac-dw  10772com-bardac-dw   48556/udp                # com-bardac-dw 10773iqobject         48619/tcp                # iqobject 10774iqobject        48619/udp                # iqobject[[email protected] ~]# 
Head-n-number and Tail-n +number usage: [[email protected] ~]# Cat-n/etc/issue | Head-n-2 1 CentOS release 6.5 (Final) [[email protected] ~]# [[email protected] ~]# Cat-n/etc/issue | Tail-n +2 2 Kernel \ r on an \m 3[[email protected] ~]#

This article from "Love Open source, happy to share!" "Blog, be sure to keep this provenance http://hezhanglinux.blog.51cto.com/10861477/1710965

Text Processing command series--head and tail

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.