在 Ubuntu(以及大多数 Linux 发行版)中,alias(别名) 分几种情况,可以用不同方式列出。下面按常见场景说明。
alias
或
alias -p
输出示例:
alias ll='ls -l'
alias la='ls -A'
alias grep='grep --color=auto'
alias ll
如果未定义,不会有输出。
alias 通常定义在以下文件中(顺序加载):
~/.bashrc
~/.bash_aliases
~/.profile
~/.bash_profile
/etc/bash.bashrc
/etc/profile
grep -R "ll" ~/.bashrc ~/.bash_aliases ~/.profile /etc/bash.bashrc 2>/dev/null
Ubuntu 默认会在 .bashrc 中定义一些常见 alias,例如:
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
查看它们:
grep alias ~/.bashrc
有时你以为的是 alias,其实是 shell 函数:
type ll
输出示例:
ll is aliased to `ls -l'
或:
ll is a function
declare -f # 所有函数
alias # 所有 alias
| 类型 | 是否重启失效 |
|---|---|
直接在终端执行 alias |
✅ 失效 |
写在 ~/.bashrc |
❌ 永久 |
写在 /etc/bash.bashrc |
❌ 全局永久 |
source ~/.bashrc
alias > ~/my_aliases.txt
如果你愿意,我可以帮你:
只要告诉我你用的是 bash / zsh / fish 即可。