Summary of linux Command for viewing File Content

Source: Internet
Author: User

In linux, there are many commands that can view the file content. Various commands have different usage and features, you can select the appropriate commands as needed to quickly and efficiently view the file content. The following is a summary of the commands for viewing the file content in linux.

Cat displays content starting with the first line and outputs all content

Tac displays the content in reverse order from the last line and outputs all the content

More according to the window size, the actual file content on one page

Less is similar to more, but it has the advantages of turning pages forward and searching for characters.

The head displays only the first few rows.

Tail only displays the last few rows

Nl is similar to cat-n and displays the output row number.

The following describes the usage of various commands as follows:

1. cat command

Cat Syntax: cat [-n] File Name

Parameter description:-n: The line number is output together when it is displayed.

The cat function is to continuously output content from the first line to the screen. However, cat is not commonly used, because when the file size is large and the number of rows is large, the screen cannot be fully stored, only part of the content can be seen.

The tac function is to output content data from the last line to the screen. We can find that tac is actually written by cat in turn.

2. tac command

Tac Syntax: tac file name

The content of the file output by this command and the content output by cat are completely reversed. Generally, it is rarely used without abnormal demands.

3. more command

More Syntax:

More file name

The more function is to output the file content from the first line according to the size of the output window. When a page cannot be output in full, you can use the "Enter key" to Flip three lines down (my environment is three lines, and other linux versions may be different), or use the "Space key" to flip the page down. Exit the view page. Press "q. This is a common command.

In addition, more can be used with the Pipeline character "|" (pipe), for example, ls-al | more

4. less command

Less Syntax:

Less file name

The features of less are similar to those of more, but more cannot be used to flip the page forward. You can use the [pageup] and [pagedown] keys to flip pages before and after pages, which makes it easier.

In addition, less also provides a function to search for the content you want to find in the file. If you want to find the www.phpernote.com string in the passwd file, you can do this:

[Sylar @ UB2 etc] # less passwd

Then enter:

/Www.phpernote.com

Enter

If the www.phpernote.com string exists, linux will highlight the character.

Exit the view page. Press "q.

5. head command

Head Syntax:

Head [-n number] File Name

Head is usually used when you only need to read the first or last few lines of the file.

For example:

[Sylar @ UB2 etc] # head-n 5 error. log -- only displays the first five lines of the error. log file.

6. tail command

Tail Syntax:

Tail [-n number] File Name

The tail function is the opposite of the head function. Only the last few lines of content are displayed. The usage is the same. Here we will not give an example.

7. nl command

Nl Syntax:

Nl file name

The functions of the nl command are the same as those of cat-n. It also outputs all content from the first line and displays the row number.

Articles you may be interested in
  • How many lines of files can be viewed in linux?
  • Linux File Content statistics command wc command usage details
  • Linux chmod (file or folder permission setting) command parameters and Usage Details
  • Delete files in linux. Detailed explanation of the rm command for folder commands
  • Create a folder (mkdir) command in linux
  • Prohibit web page right-click, copy, save as, View Source file and other functions to implement web page source code protection
  • Linux File Creation (touch) command details
  • Linux File Management

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.