在 Ubuntu 中,要让 alias 永久生效,关键是把 alias 写进 shell 的启动配置文件里。最常见的是 bash,如果你用 zsh 则配置位置不同。
echo $SHELL
/bin/bash → 用 bash/usr/bin/zsh → 用 zshnano ~/.bashrc
在文件末尾添加,例如:
alias ll='ls -alF'
alias gs='git status'
保存后执行:
source ~/.bashrc
✅ 以后每次打开终端都会生效
有时 SSH 登录不会加载 .bashrc,可编辑:
nano ~/.bash_profile
添加:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
nano ~/.zshrc
添加 alias:
alias ll='ls -alF'
保存后:
source ~/.zshrc
sudo nano /etc/bash.bashrc
或
sudo nano /etc/profile
添加 alias,对所有用户生效。
source~/.bashrc/etc/profile.d/xxx.sh如果你愿意,可以告诉我:
我可以帮你写完整示例。