Head&&tail

Source: Internet
Author: User

Refer to "Linux Shell Script Raiders 2nd Edition"

1,head

A) print the first 10 lines:

[Email protected]:~$ head file


b) Print the first 5 lines:

[email protected]:~$ head-N 5 file or [email protected]:~$ head-5 file


c) Print all lines except for the last M line:

[email protected]:~$ head-n-m file


2,tail

A) print the last 10 lines of the file:

[email protected]:~$Tail file


b) Print the last 5 lines:

[email protected]:~$tail-N 5 file or [email protected]:~$Tail -5 file


c) Print all rows except for the first m line:

[email protected]:~$tail -n + (m+1) file

d) Tail-f can keep a close eye on the new additions in the file and continue to update as the data increases, which can be added with a sleep interval-s so that we can set the time interval for the watch file (if the fun keeps appending data to the monitored file, tail-f Will always be executed know the process fun end ):

Pgrep Fun | Xargs tail-f file-s--pid

Pidof Fun | Xargs tail-f file-s--pid

Head&&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.