在 CentOS 系统中,要让 aliases 持久化,你需要将它们添加到相应的配置文件中。以下是一些常见的方法:
alias myalias='your-command' 将你的 alias 添加到 /etc/bashrc 文件中。首先,使用文本编辑器打开文件:
sudo vi /etc/bashrc 然后,在文件的末尾添加你的 alias,例如:
alias myalias='your-command' 保存并关闭文件。要使更改生效,请运行以下命令:
source /etc/bashrc 将你的 alias 添加到用户的 ~/.bashrc 或 ~/.bash_profile 文件中。首先,使用文本编辑器打开文件:
vi ~/.bashrc 或者
vi ~/.bash_profile 然后,在文件的末尾添加你的 alias,例如:
alias myalias='your-command' 保存并关闭文件。要使更改生效,请运行以下命令:
source ~/.bashrc 或者
source ~/.bash_profile 将你的 alias 添加到 /etc/bashrc.d/ 目录下的一个新文件中,例如 my_aliases.sh。首先,使用文本编辑器创建并打开文件:
sudo vi /etc/bashrc.d/my_aliases.sh 然后,在文件中添加你的 alias,例如:
alias myalias='your-command' 保存并关闭文件。接下来,确保 /etc/profile.d/ 目录下有一个名为 bashrc 的符号链接,指向 /etc/bashrc。如果没有,请创建一个:
sudo ln -s /etc/bashrc /etc/profile.d/bashrc 最后,重新加载 /etc/profile.d/bashrc 文件以应用更改:
source /etc/profile.d/bashrc 这样,你的 alias 将对特定用户组持久化。