温馨提示×

centos如何列出所有aliases

小樊
48
2026-07-08 19:37:19
栏目: 智能运维

CentOS(以及大多数 Linux 发行版)中,列出所有 aliases(别名) 的方法如下:


1️⃣ 列出当前 shell 中定义的所有别名

alias

alias -p

✅ 这是最常用的方法,会显示当前 shell(如 bash)中已生效的所有别名。

示例输出:

alias cp='cp -i'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias mv='mv -i'
alias rm='rm -i'

2️⃣ 查看某个具体别名

alias ll

3️⃣ 查看别名是在哪里定义的(进阶)

常见定义位置

别名通常定义在以下文件中:

~/.bashrc
~/.bash_profile
/etc/bashrc
/etc/profile

查看某个文件中的别名定义:

grep -R "alias" ~/.bashrc
grep -R "alias" /etc/bashrc

4️⃣ 列出所有(包括未生效的)别名定义

如果你想查看 系统级 + 用户级 的所有别名定义:

grep -R "^alias" ~/.bashrc /etc/bashrc /etc/profile.d/ 2>/dev/null

5️⃣ 临时取消 / 删除别名

unalias ll

删除所有别名:

unalias -a

6️⃣ 让别名永久生效

编辑:

vi ~/.bashrc

添加:

alias ll='ls -lh'

然后执行:

source ~/.bashrc

✅ 总结

目的 命令
列出所有别名 alias
查看某个别名 alias 名称
删除别名 unalias 名称
别名定义位置 ~/.bashrc / /etc/bashrc

如果你用的是 zsh / csh / fish,命令会不同,可以告诉我你使用的 shell。

0