Linux file query commands

Source: Internet
Author: User

1. cat 2.tac 3.nl 4. more 5. less 6. head 7. tail 8.od

I. Command for directly viewing file content:
1. cat (concatenate)
Parameters:
-A: equivalent to the Integration parameter of-vET. It can list some special characters rather than blank spaces;
-B: list the row numbers. Only the row numbers are displayed for non-blank rows, and the blank rows are not marked;
-E: The ending line break character $ is displayed;
-N: print the travel number, along with the blank line, there will also be a line number, different from the parameter of-B;
-T: Click the [tab] button to display it with ^ T;
-V: Lists special characters that cannot be seen;

Example 1: view the content of the/etc/issue file.
[Root @ localhost ~] # Cat/etc/issue
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
Kernel \ r on an \ m
(Note: There is still a blank line)

Example 2: If you want to add a row number, use-n.
[Root @ localhost ~] # Cat-n/etc/issue
1 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2 Kernel \ r on an \ m
3
This method is useful for finding a specific row for large files.
If you do not want to orchestrate a blank line number, you can use "cat-B/etc/issue"
[Root @ localhost ~] # Cat-B/etc/issue
1 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2 Kernel \ r on an \ m

2. tac (reverse list)
Parameter (none)
Instance:
[Root @ localhost ~] # Tac/etc/issue
(Note: There is a blank line)
Kernel \ r on an \ m
Red Hat Enterprise Linux Server release 5.4 (Tikanga)

3. nl (add row number printing)
Parameters:
-B: Specifies the row number in two ways:
-B a: indicates that the row number (similar to cat-n) is also listed regardless of whether the row is empty or not)
-B t: if there are empty rows, do not list the row numbers in the empty row (default)
-N: The following three methods are used to list row numbers:
-N ln: the row number is displayed on the leftmost side of the screen;
-N rn: the row number is displayed on the rightmost side of the field without 0;
-N rz: the row number is displayed on the rightmost side of the field and 0 is added;
-W: number of digits occupied by the row number field

Example 1:
[Root @ localhost ~] # Nl/etc/issue
1 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2 Kernel \ r on an \ m
(There is an empty line. By default, the empty line in nl is not arranged)
Note: This file actually has three lines, and the third line is blank (no character), because it is a blank line, so nl does not add a row number. If you want to add a row number, you can do the following...
[Root @ localhost ~] # Nl-B a/etc/issue
1 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2 Kernel \ r on an \ m
3
If you want to automatically add 0 to the front of the row number, do the following...
[Root @ localhost ~] # Nl-B a-n rz/etc/issue
000001 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
000002 Kernel \ r on an \ m
000003 \
0 is automatically added to the place where your field is located. The default field is 6 digits. If you want to change it to another bit, as shown in the following figure...
[Root @ localhost ~] # Nl-B a-n rz-w 3/etc/issue
001 Red Hat Enterprise Linux Server release 5.4 (Tikanga)
002 Kernel \ r on an \ m
003

2. You can view it on pages:
4. more (one page and one page flip)
Parameters:
Space key: Indicates turning a page down;
Enter: Scroll down a row;
/String: Indicates querying down the keyword 'string' in the actual content;
: F: The file name and the number of currently displayed rows are displayed immediately;
Q: The system immediately leaves more and does not display the content of the file;
B or [ctrl]-B: Indicates turning back the page. However, this operation is only useful to files and useless to pipelines.

5. less (one page and one page flip) (the difference between l and more is that less can flip forward)
Parameters:
Space key: Scroll down a page;
[PageDown] Scroll down a page;
[PageUp] a page is displayed;
/Query the "string" function in a string;
? The "string" function for querying up strings;
N repeats the previous query (and/or? );
N repeats the previous query in reverse order (and/or? );
Q: Leave the less program;

PS: the UI and environment used by less are very similar to those of man page, because man calls less to display the content of the description file.

3. data selection:
6. head (retrieve the first few rows)
Parameters:
-N: Followed by a number, which indicates the meaning of several rows.

The first 10 rows are displayed by default. If you want to change them, as shown in the following figure...



If none of the following 135 rows of data is printed, you can do this...

7. tail (remove the following lines)
Parameters:
-N: Followed by a number, which indicates the meaning of several rows.
-F: indicates the name of the file followed by the continuous detection. you must press [ctrl]-c to end the tail detection.
Example 1:
[Root @ localhost ~] # Tail/etc/man. config
By default, the last 10 rows are displayed. to display the last 20 rows, as shown below ..
[Root @ localhost ~] # Tail-n 20/etc/man. config
If you do not know the number of rows in/etc/man. config but want to list data after 100 rows, you can do this ..
[Root @ localhost ~] # Tail-n + 20/etc/man. config
-F example (since/etc/man. config will write data at any time, you want to make the file have data to write immediately
When displayed on the screen, use the-f parameter)
[Root @ localhost ~] # Tail-f/etc/man. config
Wait until you enter [crtl]-c to exit the detection of the tail command.
Example of tail and less: to display rows 11th to 20 of/etc/man. config, do the following...
[Root @ localhost ~] # Head-n 20/etc/man. config | tail-n 10

Iv. Non-plain text files
8. od (non-plain text files)
Parameters:
-T: can be followed by various types of output, such:
A outputs with Default Characters
C uses ASCII characters for output
D (size) uses decimal to output data. Each integer occupies size bytes.
F (size) uses floating point to output data. Each number occupies size bytes.
O (size) uses eight bytes to output data. Each certificate occupies size bytes.
X (size) uses the hexadecimal format to output data. Each integer occupies size bytes.

Example 1: use ASCII to output/usr/bin/passwd content
[Root @ localhost ~] # Od-t c/etc/issue
0000000 R e d H a t E n t e r p r I
0000020 s e L I n u x S e r v e r
0000040 r e l e a s e 5. 4 (T I k
0000060 a n g a) \ n K e r n e l \ r
0000100 o n a n \ m \ n

0000112 Example 2: Use the/etc/issue file to list the table of storage values and ASCII values in octal.
[Root @ localhost ~] # Od-t oCc/etc/issue
0000000 122 145 144 110 141 164 105 156 164 145 162 160 162 151
R e d H a t E n t e r p r I
0000020 163 145 040 114 151 156 165 040 170 123 145 162 166 145 040
S e L I n u x S e r v e r
0000040 162 145 154 145 141 163 145 040 065 056 064 040 050 124 151
R e l e a s e 5. 4 (T I k
0000060 141 156 147 141 051 012 113 145 162 156 145 040 154 134 040
A n g a) \ n K e r n e l \ r
0000100 157 156 040 141 156 040 134 155 012 012
O n a n \ m \ n
0000112

Summary: Both nl and cat and tac display all the data on the screen at one time;
If you want to flip one page at a time, you can use the more and less commands. You can also use them interactively, such
[Root @ localhost ~] # Od-t oCc/usr/bin/passwd | more, but the last line shows "more". If more is used for direct output, the last line shows the percentage.

Linux basic commands

Linux Command cd

Cat for Linux commands

Linux Command alias/unalias

Linux Command Parsing: su root and su-root

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.