Linux text File view, show commands: Cat head tail grep more less NL

Source: Internet
Author: User

Linux text File View, show commands: Cat head tail grep more less NL
1. Cat Displays the file Contents command.

Command format: #cat [[options]] < file list >
Common options:
    • -B, calculates all non-empty output lines, starting with a line number of 1.
    • -N, all output lines (including blank lines) are computed, and the start line number is 1.
    • -S, replacing multiple empty lines that are connected with a blank line.
    • -E, add the $ symbol at the end of each line to make it easy to confirm each line because some of the lines are too long and are represented on the display as multiple lines on the display.

Instructions for using the command:
Example:
Example A: Add the Textfile1 file contents to the line number and enter the Textfile2 file.
#cat-N textfile1 > Textfile2
Example B: Append the contents of the Textfile1 and Textfile2 files to the textfile3 after adding the line number (blank line not added)
#cat-B textfile1 textfile2 >> textfile3
Example C: Displays the contents of the/etc/fstab file.
#cat/etc/fstab
2, head view file Header content command.
Command format:# head [[Options]] < file list >
Common options:

    • -C,--bytes=size, prints the size byte content at the beginning of the file.
    • -N,--lines=number, prints the number line at the beginning of the file, and defaults to the first 10 lines of output.
    • -Q, indicating that the header of the file name is not displayed.
    • -V, which indicates the header of the file name to display.

Instructions for using the command:
Using this command is primarily used to display the contents of my head file. To confirm that it is not the file that we want to open or find.
Example:
Example A: For example, my/mnt/d directory has a filename "readme.txt", I want to see its first few lines of content, available commands:
# Head/mnt/d/readme.txt
Macromedia
Flash Player 6 for Linux
Mozilla Plug-in and Standalone players
Update Version 6.0r79
4 March 2003
New in this Version
-------------------
Find for the Dir
3, tail view file tail content command.
Command format:# tail [[options]] < file list >
Common options:

    • -C,--bytes=size, prints the last size byte content of the file.
    • -N,--lines=number, prints the last number line of the file, by default it outputs the first 10 lines.
    • -Q, indicating that the header of the file name is not displayed.
    • -V, which indicates the header of the file name to display.

Instructions for using the command:
Using this command is mainly used to show the file my tail content. To confirm that it is not the file that we want to open or find.
Example:
Example a: In the above example, if you want to see the contents of the following 10 rows, the command can be used:
#tail/mnt/d/readme.txt
2) Browser version
3) reproducible steps including a URL to the Web site where the
Problem was encountered.
If We need further information about a bugs, you'll be contacted. An
Automated reply is sent to assure and we have received your
Bug report. Due to the volume of mail received we is not able to
Individually respond to each report.
4. grep finds the file Contents command.
Command format:#grep [[options]] < matching characters > < file list >
Common options:

    • -C, count the matched rows
    • -L displays only the file name that contains the matching file.
    • -H, does not display the file name that contains the matching file.
    • -I, which produces a case-sensitive match, is case-sensitive by default.
    • -V, which lists the rows that do not match.

Instructions for using the command:
This command is primarily used to display a specific string in the terminal to find the content that matches a given pattern. The file list is separated by a space between each file.
Example:
Example a: Search for the matching character "text file" in file example.
#grep ' text file ' example
5, more paging display file command.
Command format: More[[options]] < file name >

Common options:

    • -C, clear a line from the beginning of the text, and then write the next line. Usually, more clears the screen and then writes each line.
    • -N, used to create a display window that can display n rows.
    • -D, which displays the action prompt: "Press space to continue, ' Q ' Quit ', in place of the more default prompt.
    • -S to compress contiguous blank lines into one line.
    • -P, without scrolling, clear the screen and display the text.

Instructions for using the command:
Use this command to display the file contents on the terminal split screen.
Example:
Example A: pagination displays the contents of the file/root/log.txt.
#more/root/log.txt
6, less paging display file command
Command format: Less[[options]] < file name >
Common options:

    • -?, Show use Help for less below the screen.
    • -A to start the query after the last line displayed on the current screen.
    • -C, rewritten from the top row down to full screen.
    • -E, which automatically exits less when the end of the file is displayed. Press the Q key to exit by default.
    • -N, remove the line number.
    • -S to compress multiple contiguous blank rows into one row.
    • -X N, which specifies that the default value of N is 8 per tab walk.
Instructions for using the command:

This command is roughly the same as the more feature, but less can be pushed forward or backward by the two keys, page up and PAGE down. And more does not have this function.

7, NL calculation file line number command

NL can automatically add a line number to the output file content! The default result is a bit different from Cat-n, NL can make the line number more display design, including the number of digits and whether auto-completion 0 and so on.

Command format: NL [Options] ... [File] ...

Command 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.

-P does not restart the calculation at the logical delimiter.

Command function:

The NL command reads the File parameter (standard input by default), computes 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 you use the-P flag, 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).

Usage examples:

Example one: List the contents of Log2012.log with NL

Command:

NL Log2012.log

Output:

[[email protected] test] # NL Log2012.log

1 2012-01

2 2012-02

3 ======[[email protected] test]#

Description

Blank lines in the file, NL does not add line numbers

Example two: The contents of Log2012.log are listed in NL, and the line number is also added to the empty bank.

Command:

Nl-b a Log2012.log

Output:

[[email protected] test] # Nl-b a Log2012.log

1 2012-01

2 2012-02

3

4

5 ======[[email protected] test]#

Example 3: Make the line number preceded by 0, unified output format

Command:

Output:

[[email protected] test] # nl-b a-n RZ log2014.log

000001 2014-01

000002 2014-02

000003 2014-03

000004 2014-04

000005 2014-05

000006 2014-06

000007 2014-07

000008 2014-08

000009 2014-09

000010 2014-10

000011 2014-11

000012 2014-12

000013 =======

[[email protected] test] # nl-b a-n rz-w 3 Log2014.log

001 2014-01

002 2014-02

003 2014-03

004 2014-04

005 2014-05

006 2014-06

007 2014-07

008 2014-08

009 2014-09

010 2014-10

011 2014-11

012 2014-12

013 =======

Description

Nl-b a-n RZ the command line number defaults to six bits, and the number of bits to adjust can be adjusted to 3 bits with the parameter-W 3.


Linux text File view, show commands: Cat head tail grep more less NL

Related Article

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.