Linux file Content Lookup

Source: Internet
Author: User
Tags comparison table touch command

direct access to the contents of a file:cat/tac/nlCommandCat (CONCATENATE)

# Cat [-abentv]

Options and number of references:

-A: Equivalent to-vet integration options. Can list some special characters rather than blanks;

-B: Lists the line numbers. Line numbers are displayed for non-blank lines only, and blank lines are not marked with line numbers;

-E: Displays the end of the break byte $.

- N : Prints the travel number. Along with the blank line there will be line numbers, Unlike the-B option;

-T: Displays the [tab] key in ^i.

-V: Lists some special characters that can't be seen

Example one: Check the contents of the/etc/issue file

# cat/etc/issue

CentOS Release 5.3 (Final)

Kernel \ r on an \m

Example two: bearing the title, assuming that the line number should be added

# cat-n/etc/issue

1 CentOS Release 5.3 (Final)

2 Kernel \ r on an \m

3

You can use "Cat-b/etc/issue" If you do not want to arrange line numbers for blank lines. Check it yourself.

Example three: Full display of the contents of the/etc/xinetd.conf (including special bytes)

# cat-a/etc/xinetd.conf

TAC (Reverse Column Display)

# tac/etc/issue

Kernel \ r on an \m

CentOS Release 5.3 (Final)

NL (Add line number to print)

# NL [-BNW] file

Options and number of references:

-B: Specifies the way the line number is specified, mainly in two ways:

-B A: Indicates that the line number (similar to cat-n) is also listed, whether or not it is a blank line.

-B T: If there is a blank line, the empty line does not list the row number (default value);

-N: List the method of line number representation, there are three main kinds:

-N LN: The line number is displayed at the left of the screen.

-N RN: The line number is displayed on the very right of its own field and does not add 0;

-N RZ: The line number is displayed on the very right of its own field. and add 0;

-W: The number of digits occupied by the line number field.

Example one: Listing the contents of/etc/issue with NL

# nl/etc/issue

1 CentOS Release 5.3 (Final)

2 Kernel \ r on an \m

Note that this file actually has three lines, and the third behavior is blank (no matter what byte), because he is blank line. So NL does not add a line number. Suppose you are sure you want to add a line number. Be able to do this:

# Nl-b A/etc/issue

1 CentOS Release 5.3 (Final)

2 Kernel \ r on an \m

3

So suppose you want to make the line number in front of your own initiative to fill 0? But this

# nl-b A-n rz/etc/issue

000001 CentOS Release 5.3 (Final)

000002 Kernel \ r on an \m

000003

Self-actively in their own field to fill 0, the default field is six digits. Suppose you want to change to a 3-digit number?

[Email protected] ~]# nl-b a-n rz-w 3/etc/issue

001 CentOS Release 5.3 (Final)

002 Kernel \ r on an \m

003

Turns out to be just 3 digits.

can be viewed on the page: More, Less# More/etc/man.config

#

# Generated automatically from Man.conf.inby the

# Configure script.

#

# man.conf from man-1.6d

.... (omitted in the middle) ....

--more--(28%) <== focus on this line!

Your cursor will be here waiting for your order.

Blank Key (space) : Represents a page down;

Enter : Represents a downward turn "line";

/ Word string : Represents the content in this display, which searches down the "string" of this keyword;

: F : Immediately displays the file name and the number of rows displayed at the moment;

Q : The representative left immediately More . The file content is no longer displayed.

b or [Ctrl]-b : The Representative page back, but this action is only useful to the file, the pipeline useless.

Less (one page, one page, Flip .)

Blank Key : Flip a Page down.

[PageDown] : Flip one page down;

[PageUp] : Flip one page up;

/ Word string : Search down the function of "string";

?

Word string : Search for the function of "string";

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

about!

)

N : Reverse repeated previous search ( and / or ? ) about! )

Q : Leave Less this program.

Data ExtractionHead (Remove the previous lines)

# Head [-N number] file

Options and number of references:

-N: followed by a number that represents the meaning of a few lines

# Head/etc/man.config

In the default case. Show the first 10 lines, to show the top 20 lines, you have to do this:

# head-n 20/etc/man.config

Example: Suppose the data in the next 100 rows is not printed. What is the best way to print just the first few lines of/etc/man.config?

# head-n -100/etc/man.config

The parameters following the-n option assume a negative number, such as the-n-100 of the example above. Represents the total number of rows before the column. But does not contain the next 100 rows.

For example. /etc/man.config co-owned 141 rows, then the above command "Head-n -100/etc/man.config" will list the first 41 lines, the following 100 lines will not print out.

Tail (remove the next few lines)

# Tail [-N number] file

Options and number of references:

-N: followed by a number that represents the meaning of a few lines

-F: Indicates that the file name is followed by a continuous detection, until [ctrl]-c] is pressed to end tail's detection

# Tail/etc/man.config

In the default case. Show the last 10 lines, to display the last 20 lines, you have to do this:

# tail-n 20/etc/man.config

Example one: Suppose you don't know how many lines/etc/man.config have. Just want to list the data after 100 rows?

# tail-n +100/etc/man.config

Example two: continuous detection of/var/log/messages content

# tail-f/var/log/messages

<== will not leave tail this command until after the input [crtl]-c].

non-plain text files:od

# OD [-t TYPE] file

Options or number of references:

-T: can be followed by various "type" output, such as:

A: Use the default bytes to output.

C: Use ASCII bytes to output

D[size]: Using decimal to output data, each integer occupies size bytes;

F[size]: Use floating point value (floating) to output data, each number occupies size bytes;

O[size]: Use octal (octal) to output data. Each integer occupies a size bytes;

X[size]: Use 16 carry (hexadecimal) to output data, each integer occupies size bytes;

Example one: Please use the/USR/BIN/PASSWD content in ASCII way to show!

# od-t C/USR/BIN/PASSWD

0000000 177 E L F 001 001 001.

0000020 002/003/001/260 4

0000040 020 E, 4, \a,

0000060 035/034/006/4/+ 4200 004 \b

0000100 4 004 \b 340 (340) 005

..... (omitted later) ....

The leftmost first column represents the number of bytes in 8. In the example above. The second column 0000020 represents the beginning of the

The content of the 16th byes (2x8).

Example two: Please/etc/issue the contents of this file in 8 into the comparison table of stored values and ASCII

# od-t Occ/etc/issue

0000000 103 145 156 164 117 123 040 162 145154 145 141 163 145 040 065

C e N T O s r e l e a S e 5

0000020 056 062 040 050 106 151 156 141 154051 012 113 145 162 156 145

. 2 (F i n a l) \ n K e r n E

0000040 154 040 134 162 040 157 156 040 141156 040 134 155 012 012

L \ r o n a n \ m \ n \ n

0000057

As seen above, you can find out what values each byte can correspond to. For example, the corresponding record value of E is 145. Turn into 10:1x8^2+4x8+5=101.

change the file time or build a new document:Touch

Linux there are, in fact, three basic change times.

Modification Time (mtime):
This time is upgraded when the "content data" of the file is changed. Content data refers to the contents of a file, not the attributes or permissions of a file.

Status Time (CTime):
When the "status" of the file changes, the time is upgraded, for example, if the permissions and attributes are changed, this time will be upgraded.

Access Time (Atime):
This read time (access) is upgraded when the contents of this file are taken.

For example, we use cat to read/etc/man.config. The atime of the file will be upgraded.

# Ls-l/etc/man.config

-rw-r--r--1 root root 4617 Jan 6 2007/etc/man.config

# ls-l--time=atime/etc/man.config

-rw-r--r--1 root root 4617 Sep 17:54/etc/man.config

# ls-l--time=ctime/etc/man.config

-rw-r--r--1 root root 4617 Sep 4 18:03/etc/man.config

By default, LS displays the file's Mtime, which is the time when the file's contents were last changed.

# Touch [-ACDMT]file

Options and number of references:

-A: Revision accesstime only.

-C: Only change the time of the file, if the file does not exist, do not create a new file;

-D: You can use the--date= "date or time" If you want to change the date instead of the current date.

-M: Change only mtime;

-T: The time after which the revision can be received instead of the current time, in the format [YYMMDDHHMM]

Example one: Create a new empty file and observe the time

# cd/tmp

# Touch Testtouch

# ls-l Testtouch

-rw-r--r--1 root root 0 Sep 21:09testtouch

Note that the size of this file is 0. In the default state, assuming that the touch is followed by a file, the file's three time (Atime/ctime/mtime) will be upgraded to the current time. If the file does not exist, a new, empty file is created on its own initiative.

Example two: Copy the ~/.BASHRC to BASHRC, and if you copy the full attribute, check its date

# cp-a ~/.BASHRCBASHRC

# ll BASHRC; Ll--time=atime BASHRC; ll--time=ctime BASHRC

-rw-r--r--1 root root 176 Jan 6 2007BASHRC <== this is mtime.

-rw-r--r--1 root root 176 Sep 21:11BASHRC <== This is atime

-rw-r--r--1 root root 176 Sep 21:12BASHRC <== This is CTime

Example three: Change case two of the BASHRC file, adjust the date to two days ago

# touch-d "2days ago" BASHRC

# ll BASHRC; Ll--time=atime BASHRC; ll--time=ctime BASHRC

-rw-r--r--1 root root 176 Sep 21:23BASHRC

-rw-r--r--1 root root 176 Sep 21:23BASHRC

-rw-r--r--1 root root 176 Sep 21:23BASHRC

Example four: Change the BASHRC date of the previous example to 2015/09/15 2:02

# touch-t 1509150202BASHRC

# ll BASHRC; Ll--time=atime BASHRC; ll--time=ctime BASHRC

-rw-r--r--1 root root 176 Sep BASHRC

-rw-r--r--1 root root 176 Sep BASHRC

-rw-r--r--1 root root 176 Sep 21:25BASHRC

Notice that the date has changed in both Atime and Mtime. But CTime is the time to record the moment.

In any case, the most common use of the Touch command is:

Create an empty file;

Revise a file date to the present (Mtime and Atime)


Reprint Please specify source: http://blog.csdn.net/lsh_2013/article/details/46336631

Linux file Content Lookup

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.