CentOS command for viewing File Content

Source: Internet
Author: User

CentOS command for viewing File Content

Cat, tac, more, less, head, tail, nl,

The most commonly used commands for displaying file content can be cat, more, and less! In addition, if we want to view a large file (several hundred MB), but we only need a few lines of words at the backend, what should we do? Haha! Use tail. In addition, the tac command can also be reached! Okay. Let's talk about the usage of each command!

Cat displays the file content from the first line
The tac is displayed from the last line. We can see that the tac is written by cat!
More page-by-page display of File Content
Less is similar to more, but it is better than more. He can flip the page forward!
Head only looks at the first few rows
Tail only looks at its tail.
When nl is displayed, the line number is output!
Od reads the file content in binary format!

Let's talk about the basic usage of each command!

· Cat
Syntax:

[Root @ test/root] # cat [-nAE]
Parameter description:
-N: The line number is printed on the screen.
-A: columns the <tab> and line break characters under DOS!
-E: only the broken line characters are listed in the DOS edited file!
Example:
[Root @ test/root] # cat ~ /. Bashrc <= display the. bashrc file.
#. Bashrc

# User specific aliases and functions
PATH = "/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin: $ PATH"
Alias rm = 'rm-I'
Alias cp = 'cp-I'
Alias mv = 'mv-I'
Alias ll = 'LS-l -- color = never'

[Root @ test/root] # cat ~ /. Bashrc-n <= show. bashrc and add the row number!
1 #. bashrc
2
3 # User specific aliases and functions
4 PATH = "/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin: $ PATH"
6 alias rm = 'rm-I'
7 alias cp = 'cp-I'
8 alias mv = 'mv-I'
9 alias ll = 'LS-l -- color = never'

[Root @ test/root] # cat-A regexp.txt
This is a cat, however, I need a dog. ^ M $
I want to "Happy" and <Happy> and/Happy/here. ^ M $
OK! ^ Ieverythins is OK ^ M $
Now, I will eat my food ^ M $
Are you ^ Ifinished your work ^ M $
What do you 123 goto where ^ M $
Displays several special symbols of the DOS file. The preceding file is used as an example,
It can be found that ^ M is the line break symbol, while $ of each line is the end of the line symbol,
As for ^ I, click <tab>!

Note:
Hey! Is there a "cat" in Linux 』?! Oh! No. cat is the abbreviation of Concatenate (continuous). Its main function is to print the content of an archive continuously on the screen! For example, in the above example, we printed the important parameter file. bashrc! If-n is added, the row number is added before each row! Cat is rarely used! After all, when the number of rows in your archive exceeds 40! It's too late to read! Therefore, it is better to use more or | more for execution! In addition, if it is a common DOS file, you need to pay special attention to some strange symbols, such as broken lines and <tab>, you have to add parameters such as-!.
 

· Tac
Syntax:

[Root @ test/root] # tac [alias name]
Parameter description:
Example:
[Root @ test/root] # tac ~ /. Bashrc <= found? Printed in reverse!
Fi
./Etc/bashrc
If [-f/etc/bashrc]; then
# Source global definitions

Alias h = 'History'
Alias lm = 'LS-al | more'
Alias ll = 'LS-l'
# Alias ll = 'LS-l -- color = never'
Alias mv = 'mv-I'
Alias cp = 'cp-I'
Alias rm = 'rm-I'

Export PATH
PATH = "/bin:/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin: $ PATH"
# User specific aliases and functions

#. Bashrc

Note:
Tac! What should I do? For details, check whether cat and tac have been found! Yes! Tac reversed cat, so its function is opposite to cat. cat is displayed on the screen consecutively from the first row to the last row 』, tac is displayed on the screen in reverse direction from the last line to the first line!
 

· More
Syntax:

[Root @ test/root] # more [region name]
Parameter description:
Example:
[Root @ test/root] # more ~ /. Bashrc <= displays the file content on one page.
[Root @ test/] # ls-al | more <= displays the ls content on one page.

Note:
More is really a useful command! I like it! When your file is too large, you can't see it clearly with cat! At this time, you can use more for action! More can also be used for pipeline execution at the same time! For example, when you execute the find command, you can use | more at the same time, then the search results can be listed on one page! Let's talk about pipeline (pipe) usage in bash shell!
 

· Less
Syntax:

[Root @ test/root] # less [producer name]
Parameter description:
Example:
[Root @ test/root] # less ~ /. Bashrc

Note:
The usage of less is more flexible than that of more. How can this problem be solved? At the time of more, we could not flip forward, but we could only look at it later. However, if less is used, haha! You can use the [pageup] [pagedown] and other buttons to access and view the file. Do you think it is easier to use it to view the content of a file !?
 
The usage and usage of more and less are very wide! First, you can "Search" in more and less images! How to proceed? We can explain it with less. If you want to know whether there is an uppercase word "GER" in the file "/etc/man. config", you can:
 

[Root @ test/root] # less/etc/man. config
Key description:
/Word: search for the string word in the/etc/man. config file.
Q: exit the less picture.

 
Then, after entering/, the cursor will move to the bottom left corner to wait for the input. At this time, you only need to enter your string, and the keyword will be automatically found for you!
 

· Head
Syntax:

[Root @ test/root] # head [-n number] [region name]
Parameter description:
-N: displays number rows.
Example:
[Root @ test/root] # head ~ /. Bashrc <= the first 10 rows are displayed by default.
[Root @ test/root] # head-n 20 ~ /. Bashrc <= show the first 20 rows!

Note:
Head is the first few lines of a file! That's right! That's it! If the-n parameter is not added, only 10 rows are displayed by default. What if only one row is required? Add "head-n 1 filename!
 

· Tail
Syntax:

[Root @ test/root] # tail [-n number] [region name]
Parameter description:
-N: displays number rows.
Example:
[Root @ test/root] # tail ~ /. Bashrc
[Root @ test/root] # tail-n 5 ~ /. Bashrc <= show only the last five rows!

Note:
A head will naturally have a tail! That's right! The tail usage is similar to the head usage, but the following lines are displayed! The default value is 10 rows. to display more than 10 rows, add the-n number parameter!
 

Example 1: If I want to display ~ /What about rows 11th to 20th of bashrc?
A:

This should not be difficult. Think about it. In rows 11th to 20th, I took the first 20 rows and then the last 10 rows, so the result is: "head-n 20 ~ /. Bashrc | tail-n 10 ", so that you can get the content between 11th and 20th rows! However, the pipeline commands are involved in this article, which must be mentioned in the third article!

 

· Nl
Syntax:

[Root @ test/root] # nl [producer name]
Parameter description:
Example:
[Root @ test/root] # nl ~ /. Bashrc

Note:
So what is nl? This is nothing. The usage of this command is similar to that of cat-n, that is, the command "line number can be printed" to view the file! It is also quite useful!
 

· Od
Syntax:

[Root @ test/root] # od [region name]
Parameter description:
Example:
[Root @ test/root] # od ~ /. Bashrc
0000000 020043 061056 071541 071150 005143 021412 052440
0000020 020162 070163 061545 063151 061551 060440 064554
0000040 071545 060440 062156 063040 067165 072143 067551
0000060 050012 052101 036510 027442 064542 035156 071457
0000100 035156 072457 071163 071457 064542 035156 072457
0000120 061057 067151 027472 071565 027562 067554 060543
0000140 061163 067151 027472 071565 027562 067554 060543
0000160 064542 035156 050044 052101 021110 062412 070170
0000200 020164 040520 044124 005012 066141 060551 020163
0000220 023475 066562 026440 023551 060412 064554 071541
0000240 036560 061447 020160 064455 005047 066141 060551
0000260 073155 023475 073155 026440 023551 021412 060440
0000300 071541 066040 036554 066047 020163 066055 026440
0000320 066157 071157 067075 073145 071145 005047 066141
0000340 020163 066154 023475 071554 026440 023554 060412
0000360 071541 066040 036555 066047 020163 060455 076154
0000400 062562 005047 066141 060551 020163 036550 064047
0000420 067564 074562 005047 021412 051440 072557 061562
0000440 066147 061157 066141 062040 063145 067151 072151
0000460 071556 064412 020146 020133 063055 027440 072145
0000500 060542 064163 061562 056440 020073 064164 067145
0000520 020056 062457 061564 061057 071541 071150 005143
0000540 000012
0000541

Note:
Well, what if there is a non-ASCII data file? For example, the binary file! I cannot see it when I use vi ~ At this time, it seems that you only need to read the entire data in the numerical method! That's the command od to read it! This item can be used to output the data in decimal or hexadecimal format! However, this item may be useful to engineers! Because the printed items are numbers or data in the memory ~~

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.