在 Linux 中,alias 默认只在当前 shell 会话有效,要想“持久化”,需要把 alias 写进 shell 的配置文件里。
alias ll='ls -l'
关闭终端后失效。
echo $SHELL
常见:
/bin/bash → bash/bin/zsh → zshnano ~/.bashrc
在文件末尾加:
alias ll='ls -l'
alias gs='git status'
保存后执行:
source ~/.bashrc
如果是 登录 shell(如 SSH),也可以写
~/.bash_profile
nano ~/.zshrc
添加:
alias ll='ls -l'
然后:
source ~/.zshrc
alias ll='ls -l'
funcsave ll
或手动写 ~/.config/fish/config.fish
sudo nano /etc/bash.bashrc
或
sudo nano /etc/profile
⚠️ 影响所有用户,谨慎使用
alias
或
type ll
~/.profile 但用的是 bash → 不生效source如果你告诉我 具体发行版 + shell,我可以给你最精确的配置方式。