Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of the method of making the alias setting take effect permanently in Linux

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

Webmasters who often use Linux console terminals should be impressed by the tedious command line of instructions and parameters. This is also the main reason why many webmasters would rather use a panel with security risks than use the console terminal command line! Fortunately, the experience of learning programming under DOS in Mingyue's early years still favors this command-line style, but it is still annoying for those command lines that are almost often used to repeat multiple inputs every time. Remember that under DOS, line batch files such as .bat can improve the efficiency of those tedious command-line integration management.

Linux is actually more convenient, that is the alias alias command!

For example: the original command to create a folder is mkdir, you can use the alias md=mkdir command to rename mkdir to md, you can also use md to create a folder conveniently and equivalently. However, the alias command is valid only for the current terminal by default, and the alias alias before the new terminal window will be effective once a new terminal window is opened. This is not practical, the following will give you a detailed description of how to make the alias setting take effect permanently under Linux. Let's take a look at the detailed introduction.

The methods are as follows:

This alias command can simplify a lengthy command line into a few letters or numeric abbreviations, so that you don't have to enter so many letters and symbols every time, and the abbreviations are completely set by yourself, which is very personalized. If you sort out a simple standard, you can improve the efficiency of the console terminal.

For example, the command to enter a site directory in LNMP can be alias as a site abbreviation, so you don't have to type it repeatedly every time, as follows:

Enter site directory command

Cd / home/wwwroot/www.mydomain.com/

Simplify commands through alias aliases

Alias mydomain='cd / home/wwwroot/www.mydomain.com/'

In this way, when you want to enter the site directory later, you only need to type mydomain, which is equivalent to running cd / home/wwwroot/www.mydomain.com/.

For example, check the memcached process ID and the command whether to run or not

Ps-ef | grep memecached

The alias alias can be simplified to:

Alias memv='ps-ef | grep memecached'

Just typing memv on the command line is equivalent to running ps-ef | grep memecached.

Although the above alias settings are cool to use, they are all "temporary", that is, as long as you close the current SSH link and log in to the console terminal again by SSH, these alias settings will become invalid, is there any way to make them work permanently? There is nothing impossible or unscientific in Linux, and the answer must be yes. Aliases set by the alias command are temporary, and for them to take effect permanently, just save these alias alias settings to the file: / root/.bashrc.

Let's see what's in the / root/.bashrc file first.

Cat / root/.bashrc

From the figure above, you can see that there are already some alias settings in it, that is, rm, cp and mv. We just need to edit / root/.bashrc to add the alias settings we need to save and exit.

Source / root/.bashrc

Then, use the source command {Note 1} to make the initialization file take effect, so that you can enter the console alias setting again through SSH without losing it, which is permanent.

Finally, share a command line alias setting for your reference:

The source command is also known as the "dot command", which is a dot symbol (.), which is the internal command of bash. Function: make Shell read into the specified Shell program file and execute all the statements in the file in turn. The source` command is typically used to re-execute the initialization file that you just modified to take effect immediately without having to log out and log back in.

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report