Home  >  Article  >  Operation and Maintenance  >  Introduction to the usage of alias command under Linux

Introduction to the usage of alias command under Linux

不言
不言forward
2018-10-17 15:55:093758browse

This article brings you an introduction to the usage of the alias command under Linux. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Recently, when I used ssh to connect to a remote machine and typed a command like ssh -i ~/.ssh/138.pem ec2-user@192.168.21.138, our operation and maintenance staff complained about it. After a while, I was given this command

1. The use of alias

The alias command is used to set the alias of the command. We can use this command to simplify some longer commands.
Use alias short command='original command option'
alias 138ssh= 'ssh -i  ~/.ssh/138.pem ec2-user@192.168.21.138'

Now you can directly use 138ssh to replace the original ssh -i ~/.ssh/ 138.pem ec2-user@192.168.21.138

View all current alias alias-p

Introduction to the usage of alias command under Linux

Delete an alias unalias command

Introduction to the usage of alias command under Linux

Then I happily used the short command and no longer had to remember the IP address of the server.

2. Persistence of alias

The next day when I was waiting for work and happily typing out my short command, I discovered that

Introduction to the usage of alias command under Linux

Hurry up and ask the operation and maintenance brother, and then tell me that alias needs to be reset every time it is restarted
???Then how can I play with it
Fortunately, the operation and maintenance brother taught me another trick

will Add the alias command to /etc/.bashrc or ~/.bashrc file so that you don’t need to reset it every time you restart.
/etc/.bashrc is effective for all users, and ~/.bashrc is effective for the current user
ps: My system is Deepin Linux. What I modified is /etc/bash.bashrc

Finally execute the short command of source /etc/bash.bashrc command alias setting and it can be used again

Note: source Filname is in the current bash environment Read and execute the command in FileName

The above is the detailed content of Introduction to the usage of alias command under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete