Use the head, tail, and sed commands to view text files in Linux

Source: Internet
Author: User

When you need to view the header or tail of a text file, the head command and tail command can easily complete this operation. The head command is used to view the beginning of a text file, while the tail command is used to display the last few lines of the text file. The two commands are as follows:
Head example.txt displays the top 10 lines of example.txt;
Head-N 20 example.txt displays the first 20 rows of content in the file example.txt;
Tail example.txt displays the last 10 lines of example.txt;
Tail-N 20 example.txt displays the last 20 lines of content in the file example.txt;
Tail-F example.txt displays the last 10 lines of example.txt file. After the file content is added, the new file content is automatically displayed.
Note:
The last command is very useful, especially when monitoring log files, you can always display new log information on the screen. 

You can use the SED command to view the middle part of the file, for example:
Sed-n'5, 10p'/etc/passwd
In this way, you can only view rows 5th to 10th of the file.

 

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.