Linux commands (7)---common display content commands

Source: Internet
Author: User

1. cat command; cat-concatenate files and print on the standard output

function

Display the contents of a file at once, so that if there is enough file content, it will show only the last page,

Syntax

Cat [option] filename

Options

-N: Indicates the line number of the printed file content when displaying the contents of the file-B: A line number for a non-empty output line number, that is, a row with a file content, and a space is the file content-S: A blank line that encounters two consecutive lines, automatically replaced with a blank row-e: Represents the $ symbol at the end

2. Head command: Head-output the first part of files

function

Indicates that the output file contents are displayed from the first line to the specified line, and the header 10 lines are displayed by default.

Syntax

Head [option] filename

Options Common options

-N #: Indicates that the header # line of the specified file is displayed, #表示数字

3. Tail command: Tail-output the last part of the files

function

Indicates that the output file contents are displayed from the last line to the specified line, and the trailing 10 lines are displayed by default

Syntax

tail [option] filename

Options Common options

-N #: Indicates the end of the display file # line, #表示数字

4. More command: More-file perusal filter for CRT viewing

function

Display the contents of the file in pagination mode, so that the reader can easily view, display to the last line to exit, not echo

Syntax

More [option] filename

"Subcommands"

Press SPACEBAR [space] to turn one page at the end of the file

Press ENTER [Enter] to flip one line to the end of the file (next line)

Press the Q key to exit the display file contents

Press the H key to turn the file header page


5. Less command: Less-opposite of more

function

The type more command is used to display the contents of the file in pagination, can be echoed, display to the end of the file does not actively exit, you need to press the Q key to exit the display file file contents

Syntax

less [option] filename


"Instance 1" Cat command

[[email protected] ~]# cat /etc/issue  //does not show line number centos release 6.5  (Final) Kernel \r on an \m [[email protected] ~]# cat -n /etc/issue    //Display line number add-N option     1  CentOS release 6.5  (Final)     2  kernel \r on an \m    3[[email  protected] ~]# cat -nb /etc/issue  //do not display blank lines     1   CentOS release 6.5  (Final)     2  kernel \r on  an \m [[email protected] ~]# cat -nbe /etc/issue   // Add a prompt     1  CentOS release 6.5  (Final) $    at the end of a row  2  kernel \r on an \m$$[[email protected] ~]# tac /etc /issue &nbspThe  // TAC command displays the contents of the file in reverse, starting at the tail  Kernel \r on an \mCentOSrelease 6.5  (Final)

"Instance 2" head command

[[email protected] tmp]# head-n 3/etc/passwd//Indicates the first 3 rows of etc/passwd file are displayed Root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin :/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologin[[email protected] tmp]# head-n 5/etc/passwd//indicates display etc/ passwd file first 5 lines root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/ Nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin


The "Instance 3" tail command specifies the line display

[[email protected] ~]# tail-n 3/etc/passwd//indicates that the TC/PASSWD file is displayed after 3 lines tcpdump:x:72:72::/:/sbin/nologinoprofile:x:16:16: Special user account to being used by Oprofile:/home/oprofile:/sbin/nologinmysql:x:27:27:mysql Server:/var/lib/mysql:/bin /bash[[email protected] ~]# tail-n 5/etc/passwd//indicates 5 rows after the etc/passwd file is displayed postfix:x:89:89::/var/spool/postfix:/sbin/ Nologinsshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/ Nologinoprofile:x:16:16:special user account to being used by oprofile:/home/oprofile:/sbin/nologinmysql:x:27:27:mysql Server:/var/lib/mysql:/bin/bash

"Instance 4" tail command large-scale display

[[email protected] ~]# tail -n +15 /etc/passwd   // Indicates that the last line is displayed from the 15 line of the file  -15 reverse nobody:x:99:99:nobody:/:/sbin/nologindbus:x:81:81:system message bus:/ :/sbin/nologinvcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologinrpc:x:32:32:rpcbind  Daemon:/var/cache/rpcbind:/sbin/nologinabrt:x:173:173::/etc/abrt:/sbin/nologinrpcuser:x:29:29:RPC  Service user:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:anonymous nfs user:/var/lib/nfs :/sbin/nologinhaldaemon:x:68:68:hal daemon:/:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologinsaslauth:x : 499:76: "Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/ nologinsshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/ nologinoprofile:x:16:16:special user account to be used by oprofile:/home/ Oprofile:/sbin/nologinmysql:x:27:27:mysql&nbSp Server:/var/lib/mysql:/bin/bash

"Instance 5" head combined with tail

[Email protected] ~]# Head-n 20/etc/passwd | Tail-n 5//indicates the 第16-20 line to take out the file Dbus:x:81:81:system message bus:/:/sbin/nologinvcsa:x:69:69:virtual console memory owner:/ Dev:/sbin/nologinrpc:x:32:32:rpcbind daemon:/var/cache/rpcbind:/sbin/nologinabrt:x:173:173::/etc/abrt:/sbin/ Nologinrpcuser:x:29:29:rpc Service User:/var/lib/nfs:/sbin/nologin


This article is from the "Perthon" blog, make sure to keep this source http://perthon.blog.51cto.com/10484057/1761880

Linux commands (7)---common display content commands

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.