Share file commands in Linux and view commands in linux

Source: Internet
Author: User

Share file commands in Linux and view commands in linux

In linux, the command for viewing log file content includes:

Cat displays the file content starting from the first line. tac is displayed from the last line. It can be seen that tac is the line number output when cat is written down to nl display! More the content of the displayed file on one page is less and more similar, but it is better than more, he can flip the page forward! The head only looks at the first few rows. The tail only looks at the tail.

You can useMan [command]For example, man cp.

Cat

Command function:

Display file content starting from the first line

Command syntax:

Cat [-AbEnTv] displays the entire file at a time. $ Cat filename2. create a file from the keyboard. $ Cat> filename can only create new files and cannot edit existing files. 3. combine several files into one file: $ cat file1 file2> file
Options and Parameters
Option Parameters
- Similar to the integration option of-vET, some special characters can be listed rather than blank;
-B List row numbers. Only the row numbers for non-blank rows are displayed. blank rows are not marked with row numbers!
-E Display the end of the broken line byte $;
-N Print the travel number, along with the blank line, there will also be a line number, different from the option of-B;
-T Click the [tab] button to display it with ^ I;
-V List special characters that cannot be seen

Check the content of the/etc/issue file:

Cat filename # displays the entire file at a time. cat> filename # creates a file from the keyboard. # Only new files can be created, and existing files cannot be edited. cat file1 file2> file # combine several files into one file
Tac

Command function:

The tac command is the opposite of the cat command. The file content is displayed from the last line. It can be seen that tac is a cat write backwards!

Command syntax:

Tac [Option]

Instance

[root@www ~]# tac /etc/issueKernel \r on an \mCentOS release 6.4 (Final)
Nl

Command function:

Displays the row number;Nl commandRead the file parameter (standard input by default), calculate the row number in the input, and write the calculated row number to the standard output. In the output, the nl command calculates the left line based on the flag specified in the command line. The input text must be written on the logic page. Each logic page has a header, body, and footer section (you can leave a blank section ). Unless the-p option is used, the nl command resets the row number at the beginning of each logic page. You can set a line calculation flag for the header, body, and footer sections separately (for example, the header and footer rows can be calculated, but the text rows cannot ). The default result is a little different from cat-n. nl can compare multiple display designs of the row number, including the number of digits and whether to automatically complete 0.

Command syntax:

Nl [-bnw] File

Options and parameters:

-B: Specifies the row number in two ways:
-B a: indicates that the row number (similar to cat-n) is also listed regardless of whether the row is empty or not.-B t: If the row is empty, do not list the row number (default ); -n: Used to list row numbers. There are three methods:
-N ln: the row number is displayed on the leftmost side of the screen;-n rn: the rightmost side of the row number in its own column, without adding 0;-n rz: the row number is displayed in the rightmost of its own column, and 0 is added;-w: The number of digits occupied by the column number.

Instance: Use nl to list/etc/issue content

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

Command function:

Page by page,More commandIs a text filter based on the vi editor. It displays the content of text files on pages in full screen mode, and supports keyword locating in vi. The more list contains a number of built-in shortcut keys, commonly used H (get help information), Enter (scroll down a line), Space (scroll down a screen), Q (exit command ).

Command syntax:

More (syntax) (parameter)
Option
Option Description
-<Number> Specify the number of lines displayed on each screen;
-D "[Press space to continue, 'q' to quit.]" and "[Press 'H' for instructions]" are displayed.
-C Do not perform screen scrolling. Refresh the screen each time;
-S Compress multiple empty rows into one row for display;
-U Underline prohibited;
+ <Number> It is displayed from the row of the specified number.

Instance

[Root @ www ~] # More/etc/man. config ## Generated automatically from man. conf. in by the # configure script. # man. conf from man-1.6d .... (omitted in the middle ).... -- More -- (28%) <= focuses on this line! Your cursor will be here waiting for your command

During the running of the more program, you can press the following buttons:

Space: Indicates turning one page down. Enter: Indicates turning one line down./string: Indicates searching for the keyword "string" in the displayed content;: f: The file name and the number of currently displayed rows are immediately displayed. q: The file content is no longer displayed when you leave more. B or [ctrl]-B: Indicates turning back the page. However, this action is only useful to files and useless to pipelines. Less

Command function:

The less command allows you to browse objects forward or backward, while the more command can only browse objects forward. When you use the less command to display files, use the PageUp key to flip the page up and the PageDown key to flip the page down. To exit the less program, press the Q key.

Command syntax:

Less (option) (parameter)

Option

Option Description
-E Automatically exits after the file content is displayed;
-F Force display of files;
-G Do not highlight all the keywords found. Only the currently displayed keywords are displayed to increase the display speed;
-L Case sensitivity differences are ignored during search;
-N The line number is displayed at the beginning of each line;
-S Compresses multiple empty rows into one row for display;
-S Long content is displayed on a single line without line breaks;
-X <number> Display the TAB character as a specified number of space characters.

Lab

One page and one page flip, the following instance outputs the content of the/etc/man. config file:

[Root @ www ~] # Less/etc/man. config ## Generated automatically from man. conf. in by the # configure script. # man. conf from man-1.6d .... (omitted in the middle )....: <== you can enter the command here!

The following commands can be entered during less running:

Blank key: Flip a page down; [pagedown]: Flip a page down; [pageup]: Flip a page up;/string: Search for the "string" function down; string: the "string" search function is enabled. n: Repeat the previous search (related to/or !) N: Repeat the previous search (/or related!) in reverse order !) Q: Leave the less program. head

Command function:

Head commandDisplays content starting with a file. By default, the head command displays the first 10 lines of the file.

Command syntax:

Head [-n number] File

Options and parameters:

Option Description
-N <number> Specifies the number of lines in the display header;
-C <Character Count> Specifies the number of characters in the header content;
-V The header information of the file name is always displayed;
-Q The header information of the file name is not displayed.

Example

-N: Followed by a number, which indicates the meaning of several rows.
[root@www ~]# head /etc/man.config

By default, the first 10 rows are displayed! To display the first 20 rows, you must:

[root@www ~]# head -n 20 /etc/man.config
Tail

Command function:

Extract the lines following the file,Tail commandUsed to input the end content of the file. By default, the tail command displays 10 lines at the end of the specified file on the screen. If more than one file is specified, add a file name title before each file. If no file is specified or the file name is "-", the standard input is read.

Command syntax:

Syntax:

Tail [-n number] File

Options and parameters:

Option Description
-Retry That is, when the tail command is started, files cannot be accessed or files become inaccessible later, and files are always opened. Use this option with the option "-- follow = name;
-C \ or -- bytes = \ N (N is an integer) bytes at the end of the output file;
-F \ or-follow \ Displays the latest Append content of a file. "Name" indicates that the file changes are monitored by file name. "-F" is equivalent to "-fdescriptor;
-F The function is the same as that of the "-follow = name" and "-retry" options;
-N \ or -- line = \ The content of the N (N-digit) row at the end of the output file.
-Pid = <process ID> Used with the "-f" option, the tail command is automatically exited when the process of the specified process number is terminated;
-Q or -- quiet or -- silent When there are multiple file parameters, each file name is not output;
-S <seconds> or -- sleep-interal = <seconds> Used with the "-f" option to specify the number of seconds after which the file is monitored;
-V or -- verbose When there are multiple file parameters, each file name is always output;
-Help Displays Command help information;
-Version Displays the command version.

-N: Followed by a number. It indicates the number of rows to be displayed.-f: indicates the name of the file next to the continuous detection. The tail detection will not be completed until you press [ctrl]-c.

[Root @ www ~] # Tail/etc/man. config # the last 10 rows are displayed by default! To display the last 20 rows, you have to do this: [root @ www ~] # Tail-n 20/etc/man. config

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.