在 Linux 中,alias 默认只在当前 shell 会话有效,要“持久化”需要写入 shell 的配置文件。下面按常见 shell 说明。
echo $SHELL
常见结果:
/bin/bash → Bash/bin/zsh → Zsh/bin/fish → Fish编辑用户级配置文件(推荐):
nano ~/.bashrc
在文件末尾添加:
alias ll='ls -lh'
alias gs='git status'
保存后生效:
source ~/.bashrc
如果是登录 shell(如 SSH 登录),也可以写入:
~/.bash_profile
(很多发行版会在 .bash_profile 里 source .bashrc)
nano ~/.zshrc
添加:
alias ll='ls -lh'
生效:
source ~/.zshrc
Fish 不叫 alias,叫 abbr 或 alias 函数:
alias ll 'ls -lh'
Fish 会自动写入:
~/.config/fish/config.fish
或者直接用:
abbr ll 'ls -lh'
不推荐,但可用:
/etc/bash.bashrc/etc/zsh/zshrctype ll
或
alias
alias xxx='...'(重启失效)source如果你告诉我具体 shell + 发行版,我可以给你最精确的命令。