What are the commands to view file contents in Linux system?

Time: 2017-05-11Source: Huajun News NetworkAuthor: Aotuman

Checking the contents of Linux files can be achieved by using commands. Commands such as cat, tac, more, including nl can be used to view file contents. This article will introduce through examples what commands are used to view file contents in Linux systems.

What are the commands to view file contents in Linux system?

Data will be written to /messages at any time. If you want the file to have data written to it, it will be displayed on the screen immediately. Use the -f option. It can always detect the file /var/log/messages. Newly added The data will be displayed on the screen. You will not leave tail detection until you press [crtl]-c!

Non-plain text file: od

[root@www ~]# od [-t TYPE] file

Options or parameters:

-t: Various "type (TYPE)" output can be followed, for example:

a: Use the default bytes to output;

c: Use ASCII bytes to output

d[size]: Use decimal (decimal) to output data, each integer occupies size bytes;

f[size]: Use floating point values ​​(floating) to output data, each number occupies size bytes;

o[size]:Use octal to output data, each integer occupies size bytes;

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

Example 1: Please use ASCII to display the contents of /usr/bin/passwd!

[root@www ~]# od -t c /usr/bin/passwd

0000000 177 E L F 001 001 001

0000020 002

0000040 020 E

0000060 035

0000100 4 200 004 b 340

. . . . . (Omitted later). . . .

# The first column on the left expresses the number of bytes in octal digits. Taking the above example as an example, the second column 0000020 represents the beginning of

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

Example 2: Please list the contents of the file /etc/issue in a comparison table between the stored value and ASCII in octal.

[root@www ~]# od -t oCc /etc/issue

0000000 103 145 156 164 117 123 040 162 145 154 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 154 051 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 141 156 040 134 155 012 012

l r o n a n m n n

0000057

# As shown above, you can find the value that each byte can correspond to!

# For example, the record value corresponding to e is 145, converted to decimal: 1x8^2+4x8+5=101.

Modify the file time or create a new file: touch

modification time (mtime):

When the "content data" of the file changes, this time will be updated! Content data refers to the content of the file, not the attributes or permissions of the file!

status time (ctime):

When the "status" of the file changes, this time will be updated. For example, if the permissions and attributes are changed, this time will be updated.

access time (atime):

When "the content of the file is accessed", the read time (access) will be updated. For example, if we use cat to read /etc/man.config, the atime of the file will be upgraded.

By default, ls displays the mtime of the file, which is the time when the content of the file was last modified.

[root@www ~]# touch [-acdmt] file

                   Okay, the above is all the content brought to you by the editor of Huajun. Isn’t it very simple? Have you learned it? If you want to know more related content, please pay attention to Huajun information at any time. Welcome to Huajun to download!

Related articles更多>>

Popular recommendations