如何为ubuntu创建永久的“别名”? [英] How to create a permanent “alias” for ubuntu?
问题描述
例如,如果您创建别名:
If you create an alias for example:
alias cls="clear"
它存在直到您杀死终端会话为止。当您启动新的终端窗口时,别名将不复存在。如何创建每个终端会话中都存在的永久别名?
It exists untill you kill terminall session. When you start a new terminal window the alias doesn't exist any more. How to create "permanent" alias, one that exists in every terminal session?
推荐答案
您可以在〜/中放置此类别名。 .bash_aliases文件。
You can put such aliases in the ~/.bash_aliases file.
该文件由〜/ .bashrc加载。在Ubuntu 10.04上,需要取消注释以下几行以启用〜/ .bash_aliases。在Ubuntu 11.04及更高版本上,该功能已启用:
That file is loaded by ~/.bashrc. On Ubuntu 10.04, the following lines need to be uncommented to enable the use of ~/.bash_aliases. On Ubuntu 11.04 and later, it's already enabled:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
还
您可以将以下函数添加到您的.bashrc文件中。
You can add the function below to your .bashrc file.
function permalias()
function permalias ()
{
alias "$*";
echo alias "$*" >> ~/.bash_aliases
}
然后打开一个新终端或运行源代码〜/ .bashrc在您当前的终端中。现在,您可以使用permalias命令创建永久别名,例如permalias cls = clear。
Then open a new terminal or run source ~/.bashrc in your current terminal. You can now create permanent aliases by using the permalias command, for example permalias cls=clear.
这篇关于如何为ubuntu创建永久的“别名”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!