Summary of several functions similar to Linux commands and summary of Several linux commands

Source: Internet
Author: User

Summary of several functions similar to Linux commands and summary of Several linux commands

The wc command is used to count the number of lines, characters, and bytes of text in the format of wc [parameter] text ".

-L only displays the number of rows

-W: only display the number of words

-C: only display the number of bytes

For example, count the number of users in the current system:

[Root @ linuxprobe ~] # Wc-l/etc/passwd

38/etc/passwd

 

The cut command is used to extract text characters by columns in the format of "cut [parameter] Text ".

-D delimiter specifies the delimiter. The default Delimiter is Tab.

-F indicates the number of columns displayed

-Change the unit of c to a character.

For example, obtain the names of all users in the current system:

Parameter Function:-d uses ":" As the separator. The-f parameter indicates that only the content of the first column is viewed.

[Root @ linuxprobe ~] # Cut-d:-f1/etc/passwd

 

Grep is a powerful text search tool in the format of "grep [acinv] [-- color = auto]" 'search for string' filename

-A: searches binary files for data using text files.

-C: calculates the number of times the 'search string' is found.

-I: Case sensitivity is ignored, so the case sensitivity is the same.

-N: sequential output row number

-V: reverse selection, that is, the line without the 'search string' content is displayed!

-- Color = auto: You can add the color of the keywords to the display!

Example 1: extract the/etc/passwd with the root line

# Grep root/etc/passwd or # cat/etc/passwd | grep root

Example 2: extract/etc/passwd from a root row and display the row number of these rows.

# Grep-n root/etc/passwd

 

The nl command is used in Linux to calculate the row number of a file. Nl can automatically add the row number to the output file content! The default result is a little different from cat-n. nl can do a lot of Display Design for the row number, including the function of auto-filling the number of digits.

Nl Command Format: nl [Option]... [File]...

-B: Specifies the row number in two ways:

-B a: indicates that the row number (similar to cat-n) is also listed no matter whether the row is empty or not)

-B t: If the row is empty, do not list the row number (default) for the empty row );

-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 row number is displayed on the rightmost side of its own column without 0;

-N rz: the row number is displayed on the rightmost side of its own column with a value of 0;

-W: The number of digits occupied by the row number column.

-P does not start computing again at the logical delimiters.

Example 1: Use nl to list log2012.log content, and add a row number to the blank line.

[Root @ localhost test] # nl-B a log2012.log

1 2012-01

2 2012-02

3

4

5 === [root @ localhost test] #

Example 2: Set 0 in front of the row number to unify the output format.

[Root @ localhost test] # nl-B a-n rz log2014.log

000001 2014-01

000002 2014-02

..........

000012 2014-12

000013 ====

 

[Root @ localhost test] # nl-B a-n rz-w 3 log2014.log

001 2014-01

002 2014-02

.......

012 2014-12

013 =

Note: The default line number of the nl-B a-n rz command is 6 bits. To adjust the number of BITs, add the parameter-w 3 to 3 bits.

 

Cat is a tool for viewing and connecting text files. View the content of a file. It is easy to use cat, that is, the file name is directly followed by cat.

Cat commands have three main functions:

1. display the entire file at a time. $ Cat filename

2. Create a file from the keyboard. $ Cat> filename

Only new files can be created, and existing files cannot be edited.

3. Merge several files into one file: $ cat file1 file2> file

-N or -- number indicates the number of all output rows starting from 1.

-B or -- number-nonblank is similar to-n, except that the blank row is not numbered.

-S or -- squeeze-blank when there is a blank row with more than two consecutive rows, it will replace the blank row with one row.

-V or -- show-nonprinting

Example: 1. Add the row number to the file content of textfile1 and enter the text in textfile2.

Cat-n textfile1> textfile2

2. Add the file content of textfile1 and textfile2 to the row number (blank rows are not added) and then append the content to textfile3.

Cat-B textfile1 textfile2> textfile3

3. View and number the File Content

Cat-n textfile

 

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.