In linux, run the head command and tail command to view the specified line in the file.

Source: Internet
Author: User
In linux, run the head command and tail command to view the specified lines in the file. in Linux, the most common commands for reading files are cat, more, and less. However, if you use the tail and head commands, it enables more convenient precise reading. In addition, you only need to check whether the execution of the last few lines is successful. in linux, you 'd better use the head command and tail command to check whether the specified lines in the file are in Linux, the most common commands for reading files are cat, more, and less. However, if you use the tail and head commands, it is more convenient for accurate reading. In addition, you only need to check whether the execution of the last few lines is successful. The best way is: 1. head command instance 1. default: display the first 10 lines at the beginning. 1 head/etc/passwd2: displays the first k rows. (The effect of the following three rows is the same) 123 head-k/etc/passwd (most common usage) head-n k/etc/passwdhead-n + k/etc/passwd3: displays the first k rows of multiple files, and does not display the file header of the file name. 1 head-q-n k file1 file2 file34. all contents are displayed except the last k rows. 1 head-n-k/log/syncxxx. log 2. tail command instance 1. default value. The last 10 lines are displayed. 1. tail/etc/passwd2 and display the last k rows. (The effect of the following three rows is the same) 123 tail-k etc/passwd (most common usage) tail-n k/etc/passwdtail-n-k/etc/passwd3. the last k rows are displayed, and the file header of the file name is not displayed. 1 tail-q-n k file1 file2 file34, output starting from the first k bytes. 1. the tail-n + k/etc/passwd5 and-f parameters enable the tail to read the latest content continuously. Therefore, the system can monitor the content in real time and use Ctrl + c to terminate the operation. 1 tail-f/var/log/messages and above are just some simple instances. if you use the sed command or even the awk command, it will be more powerful!
Related Article

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.