在 CentOS 里测试(查看 / 验证)aliases(别名),可以从几个层面来做,下面按常见使用场景说明。
alias
或
alias -p
输出示例:
alias ll='ls -l --color=auto'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias ll
如果已定义,会显示:
alias ll='ls -l --color=auto'
如果没有定义,不会有输出。
ll
如果 ll 是别名,实际上执行的是:
ls -l --color=auto
使用 type 命令(推荐):
type ll
输出示例:
ll is aliased to `ls -l --color=auto'
如果是普通命令:
type ls
输出:
ls is /usr/bin/ls
alias testalias='echo hello'
testalias
输出:
hello
删除测试别名:
unalias testalias
\ll
或
/bin/ls
type -a ls
示例输出:
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
~/.bashrc
/etc/bashrc
echo "alias mytest='echo test OK'" >> ~/.bashrc
source ~/.bashrc
mytest
echo $SHELL
bash ✅ 支持 aliassh ❌ 默认不支持 alias如果你在脚本里用 alias,需要:
shopt -s expand_aliases
source ~/.bashrc
✅ alias 能否看到
✅ type 命令 是否显示 aliased
✅ 是否在 bash 下
✅ 是否执行了 source ~/.bashrc
✅ 是否有别处(如脚本)覆盖了
如果你愿意,可以告诉我:
我可以直接帮你定位问题。