Beginner [Linux] basic commands "which, find, grep, wc", pipe character: " | "

Table of contents

One, which

2. find

3. grep

Four, wc

5. Pipe character " | "


One, which

1. Function: Find the program file of the command

2. Syntax: which command to find

                        No options required, just enter which command you want to find

3. Practical demonstration:

Practical demonstration:

When we enter the which pwd command, the file path of the pwd program is fed back to us below .


2. find

1. Function: Used to find specified files

2. Syntax: (1) Search by file name : find Linux path-name "file name to be found "

                        Supports wildcards

                (2) Search by file size : find Linux path-size +|-n"kMG"

3. Practical demonstration:

Practical demonstration:

We enter the find / -name tx t command.

The meaning of this command is to find the file name of txt from the root directory .

 We received a lot of feedback, but many of them were related to insufficient permissions, so we will not discuss permissions-related issues.

We enter the find / -size +1G  command

It means to find files larger than 1G in the root directory

Of course, a lot of it is virtual.

You can also use wildcards here


3. grep

1. Function: Filter out file contents by keywords from files

2. Syntax: grep [-n] keyword file path

                (1) -n option, optional, indicates that the line number of the matching line is displayed in the result

                (2) Parameter, keyword, required, indicating the keyword to be filtered out, with spaces and other special characters, it is recommended to use double quotes ""

                (3) Parameter, file path, required, indicating the file path of the filtered content, which can be used as the input port of the content

3. Practical demonstration

Practical demonstration:

We can see that the contents of the test.txt file in our current working directory are:

We enter the grep hello test.txt command

 

Add the -n option, grep -n hello test.txt , and it will show us the line number

 This can also be used with wildcards


Four, wc

Function: Used to count the number of lines, number of words, etc. in the file content

Syntax: wc -[cmlw] file path (without options: number of lines, number of words, number of bytes)

                -c option: counts the number of bytes in the file content

                -m option: Count the number of characters in the file content

                -l option: counts the number of lines in the file content

                -w option: Count the number of words in the file content

                Parameters: file path, the file to be counted, which can be used as the content input port

Practical demonstration:

Practical demonstration:

Enter the wc test.txt command

No options: Default is number of lines, number of words, number of bytes


5. Pipe character "| "

Function: Use the result of the command on the left side of the pipe character as the input of the command on the right side (can be nested)

Practical demonstration:

Practical demonstration:

Enter the cat hello.txt | wc -w command, which means that the output of viewing the contents of the hello.txt file is used as the input of the wc -w command , which means that the parameter part is omitted .


 Finally, thank you everyone for watching. I hope the audience will give you a free like.

Guess you like

Origin blog.csdn.net/cool_tao6/article/details/130860905