Linux Head and Tail commands

Source: Internet
Author: User
Tags inotify terminates

Introduction

Head and tail are a set of commands that you want to correspond to, by default showing the beginning and end of the file at 10 lines of records.

Head command

The head command displays the first n rows of the header by default

usage:head [OPTION] ... [FILE] ...default output Top 10 when specifying multiple files, output each file name before outputwhen no file is specified or the specified file is "-" the description reads the standard input mandatory arguments toLongOptions are mandatory for  Shortoptions too. -C,--bytes=[-]k Print the first K bytes of each file; With the leading '-', print all and the lastk bytes of each file shows the number of bytes before the head, here the K is the unit of the indicator, the specific units refer to the following list, when using-K display in addition to the tail of how many bytes of everything-N,--lines=[-]k print the first K lines instead of the firstTen; With the leading '-', print all and the lastK lines of each file displays the number of rows in the header, showing the header 10 rows by default, for example-n-b represents all rows except the trailing 512 lines-Q,--quiet,--Silent never print headers giving file names when more than one file is specified, the file name does not appear in the content-V,--verbose always print headers giving file names--help Display ThisHelp and exit--version output version information and EXITK may have a multiplier suffix:b +Kb +K1024x768, MB +* +M1024x768*1024x768, GB +* +* +G1024x768*1024x768*1024x768, and so on forT, P, E, Z, Y.

Tail command

Tail command with head name exactly the opposite, tail default output trailing 10 lines

usage:tail [OPTION] ... [FILE] ...default output Tail 10 when you specify multiple files, the file name is displayed by default before the content is outputWhen no file is specified or the specified file is "-", read the standard input mandatory arguments toLongOptions are mandatory for  ShortOptions too. The short option for parameters that cannot be ignored for long options is also not negligible-C,--bytes=k output the last K bytes; Alternatively, Use-c +K shows the number of bytes in the tail, when using the +k parameter indicates starting at the end of the K-byte, for example,-c +1b displaying 512 bytes beginning to the end of the content to output bytes starting with the K Th of each file-F,--follow[={name|Descriptor}] Output appended data asThe file grows; -F,--follow, and--follow=descriptor is equivalent append to display the latest content of the file-F Same as--follow=name--retry is equivalent to using the-f filename--retry operation-N,--lines=k output the last K-lines, instead of the lastTenThe default display of 10 lines of output tail, when using the +k parameter refers to starting from the beginning of line K to the end, for example,-n +6 shows the 6th line to the end of the content or use-N +K to output lines starting with the Kth--max-unchanged-stats=N with--follow=name, reopen a FILE which have not changed size after N (default 5) iterations to seeifit has been unlinked or renamed ( This  isThe usual Caseof rotated log files). With INotify, ThisOption israrely useful. --pid=pid with-F, terminate after process ID, PID dies--Specifies the process ID, can be used in conjunction with the-f parameter, and the display terminates when the specified process terminates-Q,--quiet,--silent never output headers giving file names # # #同时显示多个文件时不输出文件名--retry keep trying to open a file even when it isor attempt to reconnect becomes inaccessible when the connected file is suddenly inaccessible; useful when following by Name, i.e., with--follow=name-S,--sleep-interval=n with-f, sleep forapproximately N seconds when using the-f parameter, use-s to display the interval (default 1.0) between iterations. With INotify and--pid=p, check process p at least once every N seconds. -V,--verbose always output headers giving file names--help Display ThisHelp and exit--version output version information and exitif the first character of K (the number of bytes or lines) isA ' +',Print beginning with the Kth item fromthe start of each file, Otherwise,print the last K itemsinchThe file. K May has a multiplier suffix:b +Kb +K1024x768, MB +* +M1024x768*1024x768, GB +* +* +G1024x768*1024x768*1024x768, and so on forT, P, E, Z, Y.

Tail command parameters and head concept is similar, but to pay attention to the +k,-k of the respective meaning of the two, tail has a very interesting parameter is the-f parameter, use this parameter can not stop to display a file the latest inserted content.

Cases

1. Append Display file memory

When a file has new content inserted into it, it will not stop displaying the newly inserted content.

2.

Tail-f/tmp/orzdba_mysql.log--pid=8770

When process 8770 terminates, tail also ends

Summary

The tail-f parameter is often used to monitor the display of log files, which can be fully utilized in combination with actual needs.

Note:

pursuer.chen

Blog:http://www.cnblogs.com/chenmh

This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly give the link.

Welcome to the exchange of discussions

Linux Head and 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.