CentOS7.3 study notes summary (23)

In the Linux system, when executing certain commands, it is necessary to enter a long and long string of commands and parameters. It doesn't matter if you input them once. If such commands are often input, it seems very troublesome. The linux system provided alias alias way to solve this problem, put a long string of commands and parameters, using a short, easy to remember words instead, the implementation of the term is quite far from that period of execution commands and parameters.

Let me check what are the alias aliases in the system default ? Enter the alias command directly to view all the aliases in the system.

blob.png

We can also create our own alias:

Alias command syntax:

alias [-p] [name[=value] ... ]  

Special attention: there is no space between the equal sign and the string

Let's take a look at the above several commonly used commands: ll , ls , mv , rm . When we execute these commands, although we do not add parameters, in fact, they are automatically added to us by aliases during execution When executing mv , the mv itself does not have an overwrite prompt, and when we execute mv , if we encounter the same file name, the system will prompt whether to overwrite, and add the -i parameter by alias .

We now customize our own alias:

Implement the lxt command and output " I am zhixing !"

blob.png

This is only temporarily effective, highlighting the current user, the alias will become invalid.

Write the file permanently:

Root user: /root/.bashrc

All users: / etc / bashrc or / etc / profiles

For example: write the alias lxt = "echo I am zhixing!" Just now to the end of / etc / profile ( usually use this file).

echo “alias lxt=’echo I am zhixing! ‘">>/etc/profile

Then execute: source / etc / profile to make it effective.

The role of aliases:

    By adding some protection parameters to the dangerous command to prevent human misuse;

    As mentioned above, turn a complex string or command into a simple string or command.


Guess you like

Origin blog.51cto.com/6300167/2489215