在 Ubuntu 中查看 aliases(别名) 有几种常见方式,取决于你想查看的是当前 shell 的别名、用户自定义别名还是系统级别名。
最常用的方法:
alias
或
alias -p
输出示例:
alias ll='ls -l'
alias la='ls -A'
alias grep='grep --color=auto'
alias ll
输出:
ll='ls -l'
用户自己的别名通常写在以下文件中:
~/.bashrc(最常见)cat ~/.bashrc | grep alias
或编辑查看:
nano ~/.bashrc
~/.bash_aliasesUbuntu 默认会加载这个文件:
cat ~/.bash_aliases
~/.profile 或 ~/.bash_profilecat ~/.profile | grep alias
系统级别名可能存在于:
/etc/bash.bashrc
查看:
cat /etc/bash.bashrc | grep alias
有时你以为它是 alias,其实是函数:
type ll
输出示例:
ll is aliased to `ls -l'
或
ll is a function
不同 shell 加载的配置文件不同:
echo $SHELL
常见情况:
bash → ~/.bashrczsh → ~/.zshrcsource ~/.bashrc
| 目的 | 命令 |
|---|---|
| 查看所有别名 | alias |
| 查看某个别名 | alias 名称 |
| 查看用户别名 | cat ~/.bashrc |
| 查看系统别名 | cat /etc/bash.bashrc |
| 判断是别名还是函数 | type 命令 |
如果你愿意,可以把你当前的 Ubuntu 版本 和 shell 类型 发我,我可以帮你精确指出别名定义在哪个文件里。