Linux View File command

Source: Internet
Author: User

The Linux view log file Contents command has

    • Cat starts displaying file contents from the first line
    • The TAC is displayed in the last line, and you can see that the TAC is cat's backwards write
    • NL display, the output line number!
    • More page-by-page display file contents
    • Less is similar to more, but better than more, he can page forward!
    • Head's just a few lines.
    • Tail only look at the tail a few lines

You can use the man [command] to view the documentation for each command, such as: Man CP.

Cat

Command function:

? Show file contents starting from first line

Command syntax:

cat [-AbEnTv]一次显示整个文件。$ cat filename2.从键盘创建一个文件。$ cat > filename 只能创建新文件,不能编辑已有文件.3.将几个文件合并为一个文件: $cat file1 file2 > file
Options and Parameters
Options Parameters
-A Rather than the-vet integration option, you can list some special characters instead of whitespace;
-B Column travel number, only for non-blank lines to do line number display, blank lines are not marked line number!
-E Displays the end of the break byte $;
-N Printed travel numbers, along with blank lines, have line numbers, unlike the-B option;
-T Display the [tab] key in ^i;
-V List some special characters that can't be seen

Check/etc/issue the contents of this file:

cat filename  #一次显示整个文件.cat > filename  #从键盘创建一个文件。#只能创建新文件,不能编辑已有文件.cat file1 file2 > file   #将几个文件合并为一个文件
Tac

Command function:

? The TAC is just the opposite of the Cat command, and the file content starts from the last line, and you can see that the TAC is cat's backwards write!

Command syntax:

tac [选项]

Instance

[[email protected] ~]# tac /etc/issueKernel \r on an \mCentOS release 6.4 (Final)
nl

Command function:

? TheNL command reads the file parameter (standard input by default), calculates the line number in the input, and writes the computed line number to standard output. In the output, the NL command calculates the left line based on the flags that you specify on the command line. The input text must be written in a logical page. Each logical page has a header, a body, and a footer section (which can have an empty section). Unless the -p option is used, the NL command re-sets the line number where each logical page begins. Row calculation flags can be set separately for header, body, and footer sections (for example, header and footer lines can be computed but text lines cannot). The default result is cat -n a bit different, NL can make the line number more display design, including the number of digits and whether auto-completion 0 and so on.

Command syntax:

nl [-bnw] 文件

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 : Using NL to list/etc/issue content

[[email protected] ~]# nl /etc/issue     1  CentOS release 6.4 (Final)     2  Kernel \r on an \m
More

Command function:

? Page by page, the morecommand is a text filter based on the VI editor, which displays the contents of the text file by page in full screen, and supports keyword positioning operations in VI. There are several shortcut keys built into the more list, often with H (Get help), Enter (tumbling down one line), space (scroll down a screen), Q (Exit command).

Command syntax:

more(语法)(参数)
Options
Options Description
- <数字> Specify the number of rows to display per screen;
-D Show "[Press space to continue, ' Q ' to quit.]" and "[Press ' H ' for instructions]";
-C Does not perform a scroll screen operation. Refresh this screen every time;
-S Compress multiple blank rows into a single line display;
-U Underline is forbidden;
+ <数字> Displays the line starting with the specified number.

Instance

[[email protected] ~]# more /etc/man.config## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d....(中间省略)....--More--(28%)  <== 重点在这一行喔!你的光标也会在这里等待你的命令

In the more of this program running, you have several keys that you can press:

    • Blank Key (space): Represents a page down;
    • Enter: Represents a downward turn "line";
    • /string: Represents the keyword in this display, down search for "string";
    • : F: Immediately display the file name and the number of lines currently displayed;
    • Q: The delegate immediately leaves more and no longer displays the contents of the file.
    • b or [Ctrl]-b: Represents a page back, but this action is only useful for files and useless for pipelines.
Less

Command function:

? The less command allows the user to browse the file forward or backward, while the more command can only be browsed forward. When displaying a file with the less command, use the PageUp key to page up and PAGE down with the PageDown key. To exit the less program, you should press the Q key.

Command syntax:

less(选项)(参数)

Options

Options Description
-E After the file content is displayed, it exits automatically;
-F Mandatory display of files;
-G Do not highlight all search keywords, display only the currently displayed keywords, to improve the display speed;
-L Ignoring case differences when searching;
-N Line numbers are displayed at the beginning of each line;
-S Compress successive empty rows into one line;
-S Displays longer content in a single line, without wrapping the display;
-X <数字> Displays the tab character as a specified number of space characters.

Experiment

Page by page, the following instance outputs the contents of the/etc/man.config file:

[[email protected] ~]# less /etc/man.config## Generated automatically from man.conf.in by the# configure script.## man.conf from man-1.6d....(中间省略)....:   <== 这里可以等待你输入命令!

The commands you can enter at run time are:

    • Blank key: Flip one Page down;
    • [PageDown]: flipping down one page;
    • [PageUp]: Flip up one page;
    • /string: Search down the function of "string";
    • Word string: Search for "string" function;
    • N: Repeat the previous search (with/or?) )
    • N: Reverse the repetition of the previous search (with/or?)! )
    • Q: Leave less this program;
Head

Command function:

? The Head command is used to display the contents at the beginning of the file. By default, the head command displays the contents of the first 10 lines of the file.

Command syntax:

Options and Parameters:

Options Description
-N <数字> Specifies the number of rows to display header content;
-C <字符数> Specifies the number of characters to display the contents of the header;
-V Always display the header information of the file name;
-Q The header information for the file name is not displayed.

Example

    • -N: followed by a number that represents the meaning of a few lines
[[email protected] ~]# head /etc/man.config

By default, the previous 10 lines are displayed! To display the first 20 rows, you need to do this:

[[email protected] ~]# head -n 20 /etc/man.config
Tail

Command function:

? Take the next few lines of the file, and theTail command is used to enter the trailing content in the file. The tail command displays the last 10 lines of the specified file on the screen by default. If more than one file is given, a filename header is prepended to each file that is displayed. If no file is specified or the file name is "-", the standard input is read.

Command syntax:

Grammar:

Options and Parameters:

Options Description
--retry That is, when the tail command starts, the file is inaccessible or the file becomes inaccessible later, always trying to open the file. This option needs to be used with the option "--follow=name";
-c<n> or--bytes=<n> Output file trailing n (n is an integer) bytes of content;
-f<name/descriptor> or--follow<nameldescript> Displays the latest additions to the file. "Name" means that the file changes are monitored in the form of file names. "-F" is equivalent to "-fdescriptor";
-F Same function as option "-follow=name" and "--retry";
-n<n> or--line=<n> The output file's trailing n (n-digit) line content.
--pid= <进程号> With the "-f" option, when the specified process number process terminates, the tail command is automatically exited;
-Q or--quiet or--silent When there are multiple file parameters, do not output each file name;
-S <秒数> or <秒数> --sleep-interal= In conjunction with the "-F" option, specify the number of seconds to monitor the file change interval;
-V or--verbose When there are multiple file parameters, always output each file name;
--help Display the help information of the instruction;
--version Displays the version information for the instruction.
    • -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
[[email protected] ~]# tail /etc/man.config# 默认的情况中,显示最后的十行!若要显示最后的 20 行,就得要这样:[[email protected] ~]# tail -n 20 /etc/man.config

Linux View File command

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.