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

Introduction to the usage of alias command under Linux

不言
Release: 2018-10-17 15:55:09
forward
3779 people have browsed it

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'
Copy after login

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!

Related labels:
php
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template