Linux 如何在启动时自动加载别名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3952033/
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
How can I automatically load alias on startup?
提问by Strawberry
I am trying to add the alias ll = "ls -l"
, and I am wondering how can I load it every time I login to linux.
我正在尝试添加alias ll = "ls -l"
,我想知道每次登录到 linux 时如何加载它。
采纳答案by cschol
回答by Purge
In addition to adding it to ~/.bashrc (which only affects the current user), it can be added to /etc/profile, which will affect all users upon login.
除了添加到~/.bashrc(只影响当前用户)之外,还可以添加到/etc/profile,它会在登录时影响所有用户。
回答by Francesco Casula
You can add your aliases to ~/.bashrc
as explained by cschol but, if you prefer a tidier solution, then you can include all of your additions in one or more files.
您可以~/.bashrc
按照 cschol 的说明添加别名,但是,如果您更喜欢更简洁的解决方案,那么您可以将所有添加的内容包含在一个或多个文件中。
Many distributions already do it by default. Just add the following code to your .bashrc
file:
许多发行版已经默认这样做了。只需将以下代码添加到您的.bashrc
文件中:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
And then just add your aliases to ~/.bash_aliases
然后只需将您的别名添加到 ~/.bash_aliases