commands for displaying file contents under Linux

Source: Internet
Author: User

Environment: RedHat Linux Enterprise 6+virtual Box 4.1

Anyone who has used a DOS command should know that we can use the type command to view the contents of a file. There are five related commands under Linux that have different functions, but they are all like the type command and can only be used to view text files.

1.cat command

The cat command is most like the type command, and the method used is simple: "Cat file name." More powerful than the type command, however, is that it can view multiple files at the same time: "Cat file name is two".

2. More Commands

The more command can be used not only for paging (cat List.txt | more), but also for direct use to view file information (more list.txt).

If the text file is longer and one screen cannot be displayed, then using the Cat command may not be possible to see. Here we can simply use more to replace the Cat command. The effect is similar to the type file name/p. Use the more command to display one screen of text at a time, display full, stop, and prompt for the percentage of all content displayed, press the SPACEBAR to see the next screen.

3.less command

The less command functions almost as much as the more command, and it also shows the file by page, except that the less command allows the user to scroll forward and backward through the file while displaying the file.

Forward: Press the B key;

Turn backward: press P key;

Specify location: Enter a percentage

Exit: Q

4. Head command

The head command allows you to view only the first few lines of a file in the following format:

Head-Number of rows file name

If the number of rows is not specified, the default value of 10 is used.

5.tail command

Tail-line Number file name

corresponding to the head command, we can use the tail command to view the contents of the end of the file. Usually used for real-time

Monitors whether a file has been modified and is usually used to observe the log. Such as:

Tail-f Maillog

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.