Linux Head&tail Commands

Source: Internet
Author: User

Head and tail are all data selected by the unit of behavior, head is taken out front, tail is taken out of the back.

Head(remove the previous lines)

1. Command format:

Head [parameters] ... [File] ...

2. Command parameters:

-Q Hide file names

-V Show file name

-c< bytes > Display bytes

-n< rows > rows displayed


command example:

1. By default, the first 10 rows are displayed

[[email protected] zdw]# head 123.log 12345678910

2. Display the first 5 lines

[[email protected] zdw]# head-n 5 123.log 12345

3. The file has 21 lines, the following operation, only print the previous 6 lines, the subsequent 15 lines will not print out

[[email protected] zdw]# head-n -15 123.log 123456


Tail(take back a few lines)

1. command format;

tail[necessary parameters [selection parameters] [file]

2. Command parameters:

-F Loop Read

-Q does not display processing information

-V displays detailed processing information

Number of-c< > bytes displayed

-n< lines > Display rows

--pid=pid is shared with-F, which means that the process ends after the id,pid dies.

-Q,--quiet,--silent never output the header of the file name

-S,--sleep-interval=s is combined with-F, which means sleep s seconds at each repetition interval


command example:

1. Display the last 5 lines of the file

[[email protected] zdw]# tail-n 5 123.log 1617181920

2. List only 15 rows of data

[[email protected] zdw]# tail-n +15 123.log 151617181920

3. Cycle through the contents of a file

[[email protected] zdw]# ping www.baidu.com >123.log & Append ping information to 123.log [[email protected] zdw]# tail-f 123.log bytes from 220.181.111.188:icmp_seq=32 ttl=55 time=3.50 ms64 bytes from 220.181.111.188:icmp_seq=33 ttl=55 t  ime=3.67 ms64 bytes from 220.181.111.188:icmp_seq=34 ttl=55 time=7.14 ms64 bytes from 220.181.111.188:icmp_seq=47 ttl=55 time=3.54 ms64 bytes from 220.181.111.188:icmp_seq=48 ttl=55 time=3.33 ms64 bytes from 220.181.111.188:icmp_seq=49 ttl= time=4.24 Ms^c

Keep showing until you press CTRL + C to terminate

4. Display lines 6th through 10th of the file

[[email protected] zdw]# head-n 456.log|tail-n 5 Use the pipe to operate 678910


This article is from the blog "Write to Yourself", so be sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1765474

Linux Head&tail Commands

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.