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 [email protected]'

Now you can directly use 138ssh instead of the original ssh -i ~/.ssh/138.pem [email protected]

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

Steps and pitfalls of upgrading linux mysql5.5 to mysql5.7

Table of contents Linux MySQL 5.5 upgraded to MyS...

mysql-8.0.17-winx64 deployment method

1. Download mysql-8.0.17-winx64 from the official...

What are the new CSS :where and :is pseudo-class functions?

What are :is and :where? :is() and :where() are p...

MySQL sharding details

1. Business scenario introduction Suppose there i...

Docker image access to local elasticsearch port operation

Using the image service deployed by docker stack,...

Docker network principles and detailed analysis of custom networks

Docker virtualizes a bridge on the host machine. ...

Best Practices Guide for Storing Dates in MySQL

Table of contents Preface Do not use strings to s...

JavaScript Prototype Details

Table of contents 1. Overview 1.1 What is a proto...

Summary of some common uses of refs in React

Table of contents What are Refs 1. String type Re...

Complete steps to use vue-router in vue3

Preface Managing routing is an essential feature ...

MySQL5.7 parallel replication principle and implementation

Anyone who has a little knowledge of data operati...

Basic usage of custom directives in Vue

Table of contents Preface text 1. Global Registra...

Detailed explanation of MySQL 8.0 atomic DDL syntax

Table of contents 01 Introduction to Atomic DDL 0...