Linux self-study journey-basic commands (alias command alias)

Linux self-study journey-basic commands (alias setting command alias)


Preface

1. In the previous section, we talked about the function of the pipe symbol and its basic use. If you haven’t read it, you can click the link below to watch it: pipe symbol

2. In this section we describe the command alias that can set the command alias


Tip: The following is the content of this article

1. What is the use of alias?

  1. Command name: alias
  2. Location: /usr/bin/alias
  3. Execution authority: all users
  4. Function description: set alias to command
命令格式
alias 命令别名='命令'

For example, our ls -la command, we know that the function of this command is to display all the files in the directory and display them in a long format. But we found that it is very troublesome to type this command, and the option is followed by ls space. We don't want to type so troublesome. Then our alias can show its effect, and he can rename this command in your own way.

Second, the use of alias

1.alias command alias='command'

alias xx='nn', xx write you want to get the name for this command, nn write the command you want to use alias.

alias lll='ls -la' = I renamed the ls -la command to lll, and then I can type lll directly on the console, which is equivalent to ls -la. (Remember to copy it completely after typing this entire command, it will be useful later)

(Note: The command alias defined in this way is temporary, that is, it will be invalid next time you restart)
Insert picture description here

2. Direct alias

The following direct alias will display a bunch of existing entries, these are already defined aliases, we can see the lll we just defined, which proves that the definition is successful.
Insert picture description here

3. Permanently effective settings for the current user

1. I said earlier that the command alias set with alias xx='nn' is temporary, and it will become invalid next time you restart it, so how can you make it take effect permanently? We can edit the file /root/.bashrc.
Insert picture description here
2. But we didn't talk about vim, so just talk about it briefly. After typing this command in the above picture, press Enter to enter the following interface.
Insert picture description here
3. Press the up, down, left, and right keys on the keyboard to move the cursor, we move the cursor to the yellow alias side, and then press the letter o on the keyboard, and then remember the entire command I asked you to copy just now, just right-click and paste Then, the following situation will appear.
Insert picture description here
4. Directly press the Esc key of the keyboard, and then hold down the shift and: two keys of the keyboard. You don't need to press at the same time, first press shift and then press: OK, the following situation will appear, we find There will be one more below: No.
Insert picture description here
5. Direct input of wq on the keyboard will save and exit, and then the command alias will always take effect next time you restart.


to sum up

In this section we mainly talked about

{

1. The use
of alias : the syntax is: alias command alias='command'

}

This is Jiehua, see you next time!

Guess you like

Origin blog.csdn.net/qq313088385/article/details/114086872