#Bash 的 alias 命令
alias [-p] [NAME[=VALUE] ... ]
功能
查看或定义别名。
存在命令同名的命令时,可以在命令开头添加反斜杠(\)来抑制别名。
类型
Bash 内置命令。
参数
-p- 以开重用格式打印别名NAME- 别名VALUE- 别名的值
#示例
定义和使用别名
$ alias greet='echo Hello' # 定义别名
$ greet # 调用别名
Hello
$ greet Tom
Hello Tom
$ unalias greet # 删除别名
查看别名
$ alias # 查看所有别名
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
$ alias ls # 查看指定的别名
alias ls='ls --color=auto'
抑制别名
$ type -a ls # 查看所有可用的 ls 命令
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
$ ls # 实际执行 ls --color=auto
1.txt 2.txt dir1 dir2
$ \ls # 实际执行 /usr/bin/ls
1.txt 2.txt dir1 dir2
#相关命令
| 命令 | 说明 |
|---|---|
| unalias | 删除别名 |
#推荐阅读
#手册
alias: alias [-p] [name[=value] ... ] Define or display aliases. Without arguments, `alias' prints the list of aliases in the reusable form `alias NAME=VALUE' on standard output. Otherwise, an alias is defined for each NAME whose VALUE is given. A trailing space in VALUE causes the next word to be checked for alias substitution when the alias is expanded. Options: -p print all defined aliases in a reusable format Exit Status: alias returns true unless a NAME is supplied for which no alias has been defined.