在 CentOS 里 alias 不生效,一般就这几种常见原因,你逐条排查一下:
最常见的原因。
如果你写在:
~/.bashrc(当前用户)/etc/bashrc 或 /etc/profile(全局)改完要执行:
source ~/.bashrc
# 或
source /etc/bashrc
否则不会生效。
比如:
sh script.sh这些情况下 alias 默认不加载。
✅ 解决:
/etc/profile、~/.bash_profile~/.bashrcCentOS 默认:
~/.bashrc ← 推荐放这里
如果你写在 .bash_profile 但用的是终端,可能不生效。
检查有没有:
.bashrc 里的判断跳过排查:
alias
type 你的命令
确认当前 shell:
echo $SHELL
如果是 zsh:
~/.zshrc正确写法:
alias ll='ls -l'
❌ 错误示例:
alias ll = 'ls -l' # 有空格
直接执行:
alias test='echo hello'
test
能跑说明 shell 没问题。
vi ~/.bashrc
末尾加:
alias ll='ls -l --color=auto'
保存后:
source ~/.bashrc
如果你愿意,可以把 你写的 alias、放在哪个文件、怎么执行的 发出来,我可以直接帮你定位。