Beginners [Linux] basic commands "echo, tail", backtick " ` ", redirection character " >, >> "

Table of contents

One, echo

2. Backticks " ` "

3. Redirection characters > and >>

4. tail


One, echo

1. Function: You can use the echo command to output the specified content in the command line.

2. Syntax: echo parameter

                There are no options, only parameters, indicating the content to be output. If you want to output complex content, you can use double quotes " ".

3. Practical operation

Actual operation:

When we type echo "hello world" :

The content of hello world is output to us

When we use the echo command, we must develop the habit of using double quotes "" , because some special symbols may not be recognized when entered, so it is better to use double quotes "".

2. Backticks " ` "

1. Function: Used in conjunction with echo, by enclosing the command line with backticks " ` ", the enclosed content will be executed as a command instead of outputting the content as ordinary characters.

2. Practical operation

Actual operation:

When we want to output the contents of the pwd command, if we directly enter the command echo pwd it looks like this:

Obviously it can't be displayed 

When we add backticks " ` " and enter the echo `pwd` command :

The effect is obvious, pwd is displayed as a command.

3. Redirection characters > and >>

1. Function: > Overwrite and write the command results on the left to the file specified on the right of the symbol

                >>Append the command results on the left to the file specified on the right of the symbol

2. Use it with the echo command and demonstrate it in practice. 

As you can see, the test.txt in our current working directory has no content:

 When we enter the echo "hello linux" > test.txt command

As you can see, we wrote the entered hello linux into test.txt

 When we enter the echo "hello world" > test.txt command

hello world overwrites the content of the original test.txt and displays hello world

 When we enter the echo "hello linux" > test.txt command

We can see that hello linux is appended to the content of the original test.txt file.

Of course, we can also use commands in combination with redirectors

Enter the ls > test.txt command:

We overwrote the content output by ls into the content of the test.txt file.


4. tail

1. Function: View the content at the end of the file and track the latest changes to the file.

2. Syntax: tail [-f -num] Linux path

                Parameter, Linux path , indicates the file path to be traced.

               The -num option indicates that you want to view the file contents of the last few lines . If not selected, the default is the tenth line from the last .

                The -f option indicates continuous tracking.

3. Practical demonstration

 Practical demonstration:

We can see that the contents of the current test.txt file include these:

When we enter the tail test.txt command

Check the bottom 10 lines .

When we enter the tail -5 test.txt command:

 

Displays the content of the last 5 lines da

When we enter the tail -f test.txt command

He did not stop after displaying the last 10 lines. If other terminals modify the content, he will track it .

If we want to exit this command, we can enter the shortcut key " Ctrl + c " to exit.

 

Guess you like

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