如何在启动时自动加载别名?

时间:2022-09-11 19:48:02

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.

我正在尝试添加别名ll =“ls -l”,我想知道每次登录linux时如何加载它。

3 个解决方案

#1


16  

You can add it to your ~/.bashrc file in your home directory.

您可以将它添加到主目录中的〜/ .bashrc文件中。

For more information on .bashrc and the likes, see this question.

有关.bashrc等的更多信息,请参阅此问题。

#2


7  

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.

您可以按照cschol的说明将别名添加到〜/ .bashrc,但是,如果您更喜欢更整洁的解决方案,则可以将所有添加内容包含在一个或多个文件中。

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

#3


5  

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,这将在登录时影响所有用户。

#1


16  

You can add it to your ~/.bashrc file in your home directory.

您可以将它添加到主目录中的〜/ .bashrc文件中。

For more information on .bashrc and the likes, see this question.

有关.bashrc等的更多信息,请参阅此问题。

#2


7  

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.

您可以按照cschol的说明将别名添加到〜/ .bashrc,但是,如果您更喜欢更整洁的解决方案,则可以将所有添加内容包含在一个或多个文件中。

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

#3


5  

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,这将在登录时影响所有用户。