Linux file Content Lookup

Source: Internet
Author: User
Tags touch command

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

# Cat [-abentv]

Options and Parameters:

-A: Equivalent to-vet's integration options, you can list some special characters rather than blanks;

-B: List line numbers, line numbers are displayed for non-blank lines only, blank lines are not marked with line numbers;

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

- N : Print travel numbers, along with blank lines, with line numbers, - b the options are different;

-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: the title, if you want to add the line number?

# cat-n/etc/issue

1 CentOS Release 5.3 (Final)

2 Kernel \ r on an \m

3

If you do not want to arrange the line numbers of blank lines, you can use "Cat-b/etc/issue" to test your own

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 print)

# NL [-BNW] file

Options and Parameters:

-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);

-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: line number in its own field to the right of the display, 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, the third action is blank (no bytes), because he is a blank line, so NL does not add the line number. If you are sure you want to add line numbers, you can do this:

# Nl-b A/etc/issue

1 CentOS Release 5.3 (Final)

2 Kernel \ r on an \m

3

So what if you want the line number to be preceded by an automatic 0? But this

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

000001 CentOS Release 5.3 (Final)

000002 Kernel \ r on an \m

000003

Automatically in its own field to fill 0, the default field is six digits, if you want to change to 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 : In this display, the "string" keyword is searched downward;

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

Q : The representative left immediately More , the contents of the file are no longer displayed.

b or [Ctrl]-b : Represents a page back, but this action is only useful for files and useless for pipelines.

Less (one page, one page, Flip .)

Blank Key : Flip one 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 repeats the previous search ( and / or ? ) about! )

Q : Leave Less this procedure;

Data ExtractionHead (Remove the previous lines)

# Head [-N number] file

Options and Parameters:

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

# Head/etc/man.config

In the default case, the first 10 rows are displayed, so you need to display the top 20 rows:

# head-n 20/etc/man.config

Example: What if the next 100 rows of data are not printed and only the first few lines of/etc/man.config are printed?

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

The arguments following the-n option, if followed by a negative number, such as the-n-100 of the example above, represent all rows before the column, but do not include the next 100 rows. For example,/etc/man.config has 141 rows, 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 Parameters:

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

-F: Indicates continuous detection of the following file name, wait until [ctrl]-c] to end the detection of tail

# Tail/etc/man.config

In the default case, the last 10 lines are displayed, to display the last 20 lines, you need to do this:

# tail-n 20/etc/man.config

Example one: If you do not know a few lines of/etc/man.config, but only want to list 100 rows after the data?

# 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 parameters:

-T: The output of various types (type) can be followed, for example:

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]: The use of floating point value (floating) to output data, each occupies a size bytes;

O[size]: Using octal (octal) to output data, each integer occupies 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 table of storage value 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 shown above, you can see why each byte can correspond to a value, for example, E corresponds to a record value of 145, turn to 10:1x8^2+4x8+5=101.

To modify the file time or to build a new document:Touch

Linux There are actually three major change times.

Modification Time (mtime):
This time will be 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, if we use cat to read/etc/man.config, we will upgrade the atime of the file.

# 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 Parameters:

-A: revision accesstime only;

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

-D: You can follow the date you want to revise instead of the current date, or you can use the--date= "date or time"

-M: Modify Mtime only;

-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, three time (atime/ctime/mtime) of the file will be upgraded to the current time if the touch is followed by a file. If the file does not exist, a new, empty file is created on its own initiative.

Example two: Copy the ~/.BASHRC into BASHRC, assuming that the full attribute is copied, 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: Modify 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 recording the current time.

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

Create an empty file;

Revise a file date to current (Mtime and Atime)


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

Linux file Content Lookup

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.