Detailed explanation of the usage of the alias command under Linux

Detailed explanation of the usage of the alias command under Linux

1. Use of alias

The alias command is used to set an alias for a 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 instead of the original ssh -i ~/.ssh/138.pem ec2-user@192.168.21.138

View all current aliases alias-p

Remove an alias unalias command

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

2. Alias ​​persistence

The next day when I was at work and happily typing out my short command, I found

I quickly ran to ask the operation and maintenance brother, and then he told me that alias needs to be reset every time it is restarted.

How can we play this?

Fortunately, the operation and maintenance brother taught me another trick

Add the alias command to /etc/.bashrc or ~/.bashrc file so you don't have to reset it every time you restart.

/etc/.bashrc is effective for all users, ~/.bashrc is effective for the current user
ps: My system is deep linux and the modified one is /etc/bash.bashrc

Finally, execute the source /etc/bash.bashrc command and the short command set by alias can be used again.

Note: source Filname reads and executes the commands in FileName in the current bash environment

You may also be interested in:
  • Linux alias command writing
  • Detailed explanation of the commonly used Linux ls and alias basic commands
  • Detailed explanation of how to make alias settings permanent in Linux

<<:  Solve the Chinese garbled problem of mysql5.5 database command line under Windows 10

>>:  React diff algorithm source code analysis

Recommend

How to use & and nohup in the background of Linux

When we work in a terminal or console, we may not...

Implementation of mysql split function separated by commas

1: Define a stored procedure to separate strings ...

How to use worker_threads to create new threads in nodejs

Introduction As mentioned in the previous article...

CentOS 8 Installation Guide for Zabbix 4.4

Zabbix server environment platform ZABBIX version...

How to understand the difference between computed and watch in Vue

Table of contents Overview computed watch monitor...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

10 SQL statement optimization techniques to improve MYSQL query efficiency

The execution efficiency of MySQL database has a ...

MySQL multi-instance deployment and installation guide under Linux

What is MySQL multi-instance Simply put, MySQL mu...

Detailed explanation of the use of filter properties in CSS3

Recently, when I was modifying the intranet porta...

Navicat for MySQL 11 Registration Code\Activation Code Summary

Recommended reading: Navicat12.1 series cracking ...

React nested component construction order

Table of contents In the React official website, ...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...