Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Linux file content inspection - cat, tac, no, more, less, head, tail, od     - Linux system performance analysis and top command ps.pstree Comments (Linux)

- Redmine Installation (Linux)

- Workaround CentOS error message during compilation PHP5 common (Linux)

- Getting Started with Linux system to learn: how to get the process ID (PID) in the script (Linux)

- Java MVC CRUD examples (Programming)

- Linux reserves the rest of the file to delete several (Linux)

- MongoDB version 3.2 WiredTiger storage engine performance tests (Database)

- RedHat command line and graphical interface switching (Linux)

- C ++ Learning Notes: references (Programming)

- Linux console password solution (Programming)

- QEMU image file used: qcow2 and raw (Linux)

- Security Knowledge: How to hide a backdoor PHP file tips (Linux)

- NIC configuration parameters under Linux (Linux)

- Spring AOP custom annotation way to achieve log management (Programming)

- Linux kernel programming parameter passing between modules and function calls (Programming)

- Linux tmux tcpdump summary (Linux)

- Oracle online redefinition (Database)

- To achieve Linux Security (Linux)

- Volatile keyword in C language understanding (Programming)

- Open source backup software installed on Ubuntu Systemback 1.6.201 (Linux)

 
         
  Linux file content inspection - cat, tac, no, more, less, head, tail, od
     
  Add Date : 2016-09-30      
         
         
         
  Cat by the first line displays the file contents
tac displayed from the last row, you can see the tac is cat written backwards!
Nl time display, take the opportunity to output line numbers!
more display file contents page by page
Similar less with more, but better than more, he can forward flip!
Look at the first few lines of head
Look at the tail tail lines

od to binary way to read the file contents!

cat (concatenate)

[Root @ www ~] # cat [-AbEnTv]
Options and parameters:
-A: The equivalent -vET integration option which lists some special characters instead of just a blank;
-b: Lists the line number, line number only done for non-blank line display, blank lines are not marked line number!
-E: The end of the line break bytes $ displayed;
-n: Print the line number, along with a blank line will have line numbers, and -b options are different;
-T: The [tab] ^ I button to be displayed;
-v: list some do not see the special characters

Example 1: review / etc / issue of the content of this document
[Root @ www ~] # cat / etc / issue
CentOS release 5.3 (Final)
Kernel \ r on an \ m

Example 2: From the previous question, if the published numbers must add it?
[Root @ www ~] # cat -n / etc / issue
     1 CentOS release 5.3 (Final)
     2 Kernel \ r on an \ m
     3
# See it! You can print line numbers too! This large files looking for a particular row, a bit useless!
# If you do not want to arrange a blank line number, you can use the "cat -b / etc / issue" test yourself to see:

Example 3: The contents displayed /etc/xinetd.conf complete (contains special bytes)
[Root @ www ~] # cat -A /etc/xinetd.conf
# $
.... (Snip) ....
$
defaults $
{$
# The next two items are intended to be a quick access place to $
.... (Snip) ....
^ Ilog_type ^ I = SYSLOG daemon info $
^ Ilog_on_failure ^ I = HOST $
^ Ilog_on_success ^ I = PID HOST DURATION EXIT $
.... (Snip) ....
includedir /etc/xinetd.d$
 $
# The above results of the limited space, a lot of birds brother deleted the data. In addition, the resulting output does not have a special font,
# Brother birds above special font is to let you see the difference in the point where it wants to. Basically, in the general environment,
# Use the [tab] key blank and effect are similar pile of blank ah! We can not know the difference between the two.
# Cat -A used in this case will be able to find those blank spaces are what the heck! [Tab] will ^ he said
# Line break is based on $ byte representation, so you can find behind each row is $ ah! But byte line breaks
# In Windows / Linux is not the same, line breaks byte ^ M $ Windows is Luo.
tac (reverse listed)

[Root @ www ~] # tac / etc / issue

Kernel \ r on an \ m
CentOS release 5.3 (Final)
# Hey! A comparison with just the example above, the last line is displayed by the first Oh!
nl (add line numbers to print)

[Root @ www ~] # nl [-bnw] file
Options and parameters:
-b: Specifies the line number in the manner specified, there are two:
      -b a: indicates whether or not a blank line, also lists the line number (similar to cat -n);
      -b t: If there are empty lines, empty row do not list the line number (default);
-n: Lists the line number representation method, there are three:
      -n ln: line number in the far left of the screen display;
      -n rn: line number in their own field in the far right of the display, and does not add 0;
      -n rz: line number in their own field in the far right of the display, and add 0;
-w: line number field of the occupied places.

Example 1: The lists nl / etc / issue content
[Root @ www ~] # nl / etc / issue
     1 CentOS release 5.3 (Final)
     2 Kernel \ r on an \ m

# Pay attention to see that this document was in fact there are three lines, the third line is blank (no byte),
# Because he is a blank line, so do not add line numbers nl Oh! If it is determined to add line numbers, you can do:

[Root @ www ~] # nl -b a / etc / issue
     1 CentOS release 5.3 (Final)
     2 Kernel \ r on an \ m
     3
# Ha ha! Add line numbers to Romania - so if you want the front of the line number 0 is automatically fill it? It may be so

[Root @ www ~] # nl -b a -n rz / etc / issue
000001 CentOS release 5.3 (Final)
000002 Kernel \ r on an \ m
000003
# Hey! Automatically fill their own fields place on the field 0 of the ~ default is six figures, if you want to change the 3-digit number?

[Root @ www ~] # nl -b a -n rz -w 3 / etc / issue
001 CentOS release 5.3 (Final)
002 Kernel \ r on an \ m
003
# 3 digits only becomes Lo ~
more (flip from page to page)

[Root @ www ~] # more /etc/man.config
#
# Generated automatically from man.conf.in by the
# Configure script.
#
# Man.conf from man-1.6d
.... (Snip) ....
--More - (28%) <== focus in this line Oh! Your cursor will be here waiting for your command
Spacebar (space): on behalf of a down turn;
Enter: representatives turned down "line";
/ String: This display represents the contents of which, down the search for "string" keyword;
: F: shows the file name and the number of rows currently displayed at once;
q: Representative leave more immediately, no longer displays the contents of the file.
b or [ctrl] -b: representatives back flip, but this action only useful for documents on line useless.

[Root @ www ~] # more /etc/man.config
#
# Generated automatically from man.conf.in by the
# Configure script.
#
# Man.conf from man-1.6d
.... (Snip) ....
After / MANPATH <== input / cursor will automatically go to the bottom line waiting for input!
less (flip from page to page)

[Root @ www ~] # less /etc/man.config
#
# Generated automatically from man.conf.in by the
# Configure script.
#
# Man.conf from man-1.6d
.... (Snip) ....
: <== Here waiting for you to enter commands!
Spacebar: Scroll down one;
[Pagedown]: Scroll down one;
[Pageup]: flip up one;
/ String: Search down "string" function;
? String: Up Search "string" function;
n: Repeat the previous search (and / or related?!)
N: inverted repeat a previous search (and / or related?!)
q: less leave this program;

head (remove the first few lines)

[Root @ www ~] # head [-n number] file
Options and parameters:
-n: followed by the number that represents the meaning of a few lines display

[Root @ www ~] # head /etc/man.config
# By default, the display front ten rows! To display the first 20 lines, you have to be like this:
[Root @ www ~] # head -n 20 /etc/man.config

Example: If the data is not printed later 100 rows, only the first few lines of print /etc/man.config, what to do?
[Root @ www ~] # head -n -100 /etc/man.config

tail (a few lines later removed)

[Root @ www ~] # tail [-n number] file
Options and parameters:
-n: followed by the number that represents the meaning of a few lines display
-f: indicates continuously monitors the connected behind the file name that you want to wait until the press [ctrl] -c will end tail detection

[Root @ www ~] # tail /etc/man.config
# By default, the display of the last ten lines! To display the last 20 lines, you have to be like this:
[Root @ www ~] # tail -n 20 /etc/man.config

Example 1: If you do not know /etc/man.config a few lines, but only want to list 100 rows of data later?
[Root @ www ~] # tail -n +100 /etc/man.config

Example 2: continue to detect the contents of / var / log / messages of
[Root @ www ~] # tail -f / var / log / messages
  After <== until input [crtl] -c This command will leave the tail detection!
        A sample content on it fun! In fact, with the head -n -xx have the same purpose. When issued "tail -n +100 /etc/man.config" means the file from the later 100 lines will be listed. Likewise, in man.config 141 line, so the first 100 to 141 lines will be listed in the coming ! 99 front row will not be displayed!

        As two examples, since the / var / log / messages at any time the data will be written to the file you want to make data writing immediately displayed on the screen, you use the -f option, he can always detect / var / log / messages file, the newly added data will be displayed on the screen. Until you press [crtl] -c will leave the tail detection!

Non-text files: od

[Root @ www ~] # od [-t TYPE] file
Options or parameters:
-t: the back can take a variety of "types (TYPE)" output, for example:
      a: byte to use the default output;
      c: Use ASCII bytes output
      d [size]: use decimal (decimal) to output data, each integer occupies size bytes;
      f [size]: the use of floating point values ​​(floating) to output data, each number of occupied size bytes;
      o [size]: use octal (octal) to output data, each integer occupies size bytes;
      x [size]: use hex (hexadecimal) to the output data, each integer occupies size bytes;

Example 1: the contents of the / usr / bin / passwd using ASCII way to show!
[Root @ www ~] # od -t c / usr / bin / passwd
0000000 177 E L F 001 001 001 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0
0000020 002 \ 0 003 \ 0 001 \ 0 \ 0 \ 0 260 225 004 \ b 4 \ 0 \ 0 \ 0
0000040 020 E \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 4 \ 0 \ 0 \ a \ 0 (\ 0
0000060 035 \ 0 034 \ 0 006 \ 0 \ 0 \ 0 4 \ 0 \ 0 \ 0 4 200 004 \ b
0000100 4 200 004 \ b 340 \ 0 \ 0 \ 0 340 \ 0 \ 0 \ 0 005 \ 0 \ 0 \ 0
..... (Later omitted) ....
The first column is the leftmost # 8 into bits to represent the number of bytes. In the above example, the beginning of the second column is represented 0000020
# The first 16 byes (2x8) content of meaning.

Example 2: set / etc / issue 8 contents of this file to carry lists of stored value and the ASCII table
[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
0,000,020,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
0,000,040,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, can be found in each byte may correspond to the value why!
# Such as recording the corresponding value of e 145, conversion to decimal: 1x8 ^ 2 + 4x8 + 5 = 101.
Modify the file time or build a new file: touch

modification time (mtime):
When the "content data" of the file changes, it will upgrade this time! Content data refers to the contents of the file, rather than the property or file permissions Oh!

status time (ctime):
When "state (status)," the document changes will be upgraded this time, for example, such as permissions and attributes are changed, will be upgraded this time ah.

access time (atime):
When the "content of the file is accessible," will upgrade the read time (access). For example, we use cat to read /etc/man.config, will upgrade the atime of the file.



In case of default, ls show is mtime of the file, which is the contents of this file was last time changes.

[Root @ www ~] # touch [-acdmt] file
Options and parameters:
-a: Amendment only access time;
-c: Modify only time of the file, if the file does not exist create a new file;
-d: desire can take back the revised date without the current date, you can also use --date = "date or time."
-m: Modify mtime only;
-t: To revise the back can take time instead of the current time in the format [YYMMDDhhmm]

Example 1: Create an empty file and watch time
[Root @ www ~] # cd / tmp
[Root @ www tmp] # touch testtouch
[Root @ www tmp] # ls -l testtouch
-rw-r - r-- 1 root root 0 Sep 25 21:09 testtouch
# Note that the file size is 0 it! In the default state, if the touch followed by the file,
# Is three times the file (atime / ctime / mtime) will be upgraded to the current time. If the file does not exist,
# Will take the initiative to create a new empty file Oh! Such as the example above!

Example 2: The ~ / .bashrc copy become bashrc, assume complete copy of the property, check its date
[Root @ www tmp] # cp -a ~ / .bashrc bashrc
[Root @ www tmp] # ll bashrc; ll --time = atime bashrc; ll --time = ctime bashrc
-rw-r - r-- 1 root root 176 Jan 6 2007 bashrc <== This is mtime
-rw-r - r-- 1 root root 176 Sep 25 21:11 bashrc <== This is atime
-rw-r - r-- 1 root root 176 Sep 25 21:12 bashrc <== This is ctime
Example 3: Case bashrc file modification II, two days before the adjustment date
[Root @ www tmp] # touch -d "2 days ago" bashrc
[Root @ www tmp] # ll bashrc; ll --time = atime bashrc; ll --time = ctime bashrc
-rw-r - r-- 1 root root 176 Sep 23 21:23 bashrc
-rw-r - r-- 1 root root 176 Sep 23 21:23 bashrc
-rw-r - r-- 1 root root 176 Sep 25 21:23 bashrc
# Keep a comparative example to see, originally it became the 23rd of 25 May (atime / mtime) ~
# However, ctime does not change with Oh!

Example 4: The previous examples bashrc date to 2007/09/15 2:02
[Root @ www tmp] # touch -t 0709150202 bashrc
[Root @ www tmp] # ll bashrc; ll --time = atime bashrc; ll --time = ctime bashrc
-rw-r - r-- 1 root root 176 Sep 15 2007 bashrc
-rw-r - r-- 1 root root 176 Sep 15 2007 bashrc
-rw-r - r-- 1 root root 176 Sep 25 21:25 bashrc
# Caution look at atime and mtime date has changed, but the ctime is the current record time!
     
         
         
         
  More:      
 
- Linux System Getting Started Learning: Repair (Linux)
- Git 2.5 increase in the working tree, triangle improved workflow performance (Linux)
- SSH mutual trust configuration (Server)
- Create a custom pixel format based on an existing image data BufferedImage (Programming)
- Sturdy build secure Linux server (Linux)
- How to Debian Linux the default Python version switch to alternative version (Linux)
- Create a project using Android Studio LinearLayout (Programming)
- Developing a Web server yourself (Server)
- Python system default encoding (Programming)
- Ubuntu 12.04 commonly use shortcuts finishing Share (Linux)
- printf PHP string operations () built-in function usage (Programming)
- Spring loaded container finishes executing a method (Programming)
- Oracle 11g DataGuard service to start automatically (Database)
- Do not enter password login ssh (Server)
- Detailed Linux su command to switch users Mistakes (Linux)
- Ubuntu 14.04 Install WordPress on Nginx (Server)
- CentOS 7 RHEL 7 to reset the root password (Linux)
- View processes and threads under Linux (Linux)
- Linux Getting Started tutorial: GNU C and Vim will fight the C / C ++ IDE semi-automatic (Linux)
- MySQL fuzzy query: LIKE and REGEXP pattern mode (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.