Linux Ubuntu 10.04 中的别名存储在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9245518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:32:06  来源:igfitidea点击:

Where are alias' stored in Ubuntu 10.04

linuxubuntualias

提问by JZ.

I'm using a command which I don't know where the information is stored.

我正在使用一个我不知道信息存储在哪里的命令。

alias nup='ps ax | grep "nginx"'

Where is this alias saved?

这个别名保存在哪里?

采纳答案by ranendra

It depends upon your environment and configurations. For bash, I would generally put it in a .bashrcfile that in a home directory.

这取决于您的环境和配置。对于bash,我通常会将它放在主目录中的.bashrc文件中。

回答by dkniffin

It's ussually in a file in your home directory, such as .aliases or something.

它通常在您的主目录中的文件中,例如 .aliases 或其他内容。

回答by user unknown

Try

尝试

grep alias ~/.* 
grep alias /etc/*

to find most aliases. In /etc/default, /etc/environment, depending on your distribution (I read: ubuntu)/version there might be more in other /etc/ -subdirs.

找到大多数别名。在 /etc/default、/etc/environment 中,根据您的发行版(我读到:ubuntu)/version,其他 /etc/ -subdirs 中可能会有更多。

回答by Arvind

In ubuntu alias get stored in the .bashrcfile.

在 ubuntu 中,别名存储在.bashrc文件中。

If you are typing alias update_linux='sudo apt-get update'in the terminal, then it will create an alias temporarily. It works until you close your terminal.

如果您alias update_linux='sudo apt-get update'在终端中输入,那么它会临时创建一个别名。它会一直工作到您关闭终端。

To add an alias permanently you can edit ~/.bashrcand add the alias to it:

要永久添加别名,您可以编辑~/.bashrc别名并将其添加到其中:

gedit ~/.bashrc

gedit ~/.bashrc

and add alias at the end

并在最后添加别名

alias update_linux='sudo apt-get update'

alias update_linux='sudo apt-get update'

Don't forget to refresh the .bashrcconfiguration, by running:

不要忘记.bashrc通过运行来刷新配置:

source ~/.bashrc

source ~/.bashrc

for more details on creating alias you can read following blog: Codebucket.

有关创建别名的更多详细信息,您可以阅读以下博客:Codebucket

回答by Daniel Dropik

I am using Ubuntu 14.04, and you may put your aliases directly in .bashrc, but you may also create a file in ~/.bash_aliases, which will hold your aliases separately and load them automatically.

我使用的是 Ubuntu 14.04,您可以将别名直接放在 .bashrc 中,但您也可以在 .bashrc 中创建一个文件~/.bash_aliases,该文件将单独保存您的别名并自动加载它们。

By default, the .bash_aliases file is not there. You will need to create it, but first make sure you create it in the same directory as your .bashrc file

默认情况下, .bash_aliases 文件不存在。您需要创建它,但首先要确保在与 .bashrc 文件相同的目录中创建它

To find your .bashrc, you may use this:

要找到你的 .bashrc,你可以使用这个:

sudo find / -name .bashrc -print

sudo find / -name .bashrc -print

My output was:

我的输出是:

/root/.bashrc /home/ddropik/.bashrc /etc/skel/.bashrc

/root/.bashrc /home/ddropik/.bashrc /etc/skel/.bashrc

As mentioned by OddityOverseerand ranendra, I am probably interested in the one in my home directory, that is /home/ddropik/.bashrc. So I navigate to my home directory, cd ~/

正如OddityOverseerranendra所提到的,我可能对主目录中的那个感兴趣,即/home/ddropik/.bashrc. 所以我导航到我的主目录,cd ~/

Now create the .bash_aliases file with touch .bash_aliasesand then edit it with nano .bash_aliases. Add whatever aliases you want.

现在创建 .bash_aliases 文件,touch .bash_aliases然后使用nano .bash_aliases. 添加您想要的任何别名。

You won't be able to use your newly added aliases until you open a new terminal session, or reload your profile, --bash login

在您打开新的终端会话或重新加载您的个人资料之前,您将无法使用新添加的别名, --bash login