CentOS file content query command

Source: Internet
Author: User
Check the file content cat: displays the file content starting from the first line tac: displays the file content starting from the last line nl: displays the file content, by the way, output the row number more: the content of the file displayed on one page is less: similar to more, but it can go forward to the head page: only look at the first few lines of tail: only look at the last few lines of touch: file creation and modification of file Time cat (view conca file content)

Cat: displays the file content starting from the first line.

Tac: displays the file content starting from the last line

Nl: displays the row number.

More: displays the file content on one page.

Less: similar to more, but it can flip the page forward

Head: only the first few lines

Tail: only the last few rows

Touch: file creation and modification of file Time

 

Cat (concatenate)

Syntax:Cat [-AbEnTv]

Options and parameters:

-A: equivalent to the integration parameter of-vET

-B: list the row numbers. only the row numbers are displayed for non-blank rows.

-N: the output line number. both blank and non-blank fields are listed.

-E: Display the ending line break characters ¥

-V: lists some unreadable special characters.

-T: Press the Tab key to display it with consumer I.

 

Example:

[root@localhost tmp]# cat /etc/issueCentOS release 5.10 (Final)Kernel \r on an \m[root@localhost tmp]# cat -n /etc/issue     1  CentOS release 5.10 (Final)     2  Kernel \r on an \m     3[root@localhost tmp]# cat -A /etc/issueCentOS release 5.10 (Final)$Kernel \r on an \m$$
Add row number and print (nl)

 

 

Syntax:[Root @ www ~] # Nl [-bnw] file

Options and parameters:

-B: specifies the row number in two ways:

-B a: indicates that the row number (similar to cat-n) is also listed no matter whether the row is empty or not );

-B t: if there is a blank row, do not list the row number (default) for the empty row );

-N: used to list row numbers. There are three methods:

-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 its own column without 0;

-N rz: the row number is displayed on the rightmost side of its own column with a value of 0;

-W: The number of digits occupied by the row number column.

 

Example

[Root @ www ~] # Nl/etc/issue 1 CentOS release 5.3 (Final) 2 Kernel \ r on an \ m this file actually has three rows, the third row is blank (no bytes ), because it is a blank line, the nl will not add a line number. [root @ www ~] # Nl-B a/etc/issue 1 CentOS release 5.3 (Final) 2 Kernel \ r on an \ m 3 [root @ www ~] # Nl-B a-n rz/etc/issue000001 CentOS release 5.3 (Final) 000002 Kernel \ r on an \ m000003 automatically add 0 in the position of your own bar ~ The default field is six digits. if you want to change it to three digits? [Root @ www ~] # Nl-B a-n rz-w 3/etc/issue001 CentOS release 5.3 (Final) 002 Kernel \ r on an \ m003

 

Syntax:More | less File

 

More:

Blank key (space): indicates turning one page down;

Enter: indicates turning "one line" down 』;

/String: searches for the keyword "string" in the displayed content;

: F: displays the file name and the number of currently displayed rows immediately;

Q: The system immediately leaves more and the file content is no longer displayed.

B or [ctrl]-B: indicates turning back the page. However, this action is only useful to files and useless to pipelines.

 

Less:

Blank key: scroll down a page;

[Pagedown]: scroll down a page;

[Pageup]: returns a page up;

/String: searches down for the "string" function;

? String: the "string" search function is enabled;

N: Repeat the previous search (and/or? Related !)

N: Repeat the previous search (and/or? Related !)

Q: Leave the less program;

Example:

[root@localhost tmp]# more /etc/man.config ## Generated automatically from man.conf.in by the……..# and to determine the correspondence between extensions and decompressors.## MANBIN                /usr/local/bin/man#--More--(31%)
Extract the first few rows (head)

 

Syntax:Head [-nnumber] file

Options and parameters:

-N: followed by a number, indicating the number of rows

The default value of number is 10. when number is a negative number, it indicates listing all the preceding rows but not including the following number rows.

 

 

Remove the following lines (tail)

Syntax:Tail [-nnumber] file

Options and parameters:

-N: followed by a number, indicating the number of rows

The default value of number is 10. when number is positive (+ number), it indicates that the file will be listed after number.

 

 

File modification time | create a new file (touch)

 

Time attribute

Mtime (modificationtime): this time is updated when the file content data changes. The content data refers to the file content, excluding the file permissions and attributes.

Ctime (Statetime): this time is updated when the file state (permission and attribute) is changed.

Atime (accesstime): this time will be modified when the file content is used.

Example:

[Root @ localhost ~] # Ls-l -- time-style = long-iso/etc/man. by default, config modifies mtime-rw-r -- 1 root 4617/etc/man. config [root @ localhost ~] # Ls-l -- time = ctime -- time-style = long-iso/etc/man. config-rw-r -- 1 root 4617/etc/man. config [root @ localhost ~] # Ls-l -- time = atime -- time-style = long-iso/etc/man. config-rw-r -- 1 root 4617/etc/man. config

 

 

Syntax:Touch [-acdmt] file

Options and parameters:

-A: only modify the access time atime

-C: only the time when the file is modified. if the file does not exist, no new file is created.

-D: the date to be modified. you can also use-date = "time or date"

-M: only modify mtime

-T: The time to be modified.

 

Main functions:

Create an empty file

Modify the file date (mtime, atime)

Example:

[Root @ localhost tmp] # cp-a/etc/man. config. /newman. config [root @ localhost tmp] # ls-l -- time-style = long-iso newman. config specifies the time format-rw-r -- 1 root 4617 newman. config [root @ localhost tmp] # touch-m-t 0709150203 newman. config // only modify mtime [root @ localhost tmp] # ls-l -- time-style = long-iso newman. config-rw-r -- 1 root 4617 newman. config [root @ localhost tmp] # ls-l -- time = atime -- time-style = long-iso newman. config // only modify atime-rw-r -- 1 root 4617 newman. config [root @ localhost tmp] # touch-a-t 0809150203 newman. config [root @ localhost tmp] # ls-l -- time = atime -- time-style = long-iso newman. config-rw-r -- 1 root 4617 newman. config [root @ localhost tmp] # [root @ localhost tmp] # touch-d "2 days ago" newman. config // atime and mtime [root @ localhost tmp] # ls-l -- time = atime -- time-style = long-iso newman are modified by default. config-rw-r -- 1 root 4617 newman. config [root @ localhost tmp] # ls-l -- time-style = long-iso newman. config-rw-r -- 1 root 4617 newman. config
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.