alias 为原命令设置别名
1. alias
1). 语法: alias 别名=‘指令名称’ //注意:=(等号)两边是没空格的
eg: alias c='clear'
2). 如果alias不加任何参数,即只输入命令alias,那么列出目前所有的别名设置。
[root@localhost ~]# alias
alias c='clear'
alias cp='cp -i'
.....
3). alias 此次的设置效用仅作用于本次登陆(即此次打开终端设置好别名,这个别名只在当前终端有效,如果关闭当前终端,再次打开其他终端此次设置都不再有效)
如果想当前用户每次登陆(即当前用户打开一个终端)都能使用别名,可在自己的 ~/.bashrc 中设定指令的别名。但是别名并不能立即使用,只能待另外打开终端才能用。如果想配置文件修改后立即生效,可以使用‘点命令’ source,source命令通常用于重新执行刚修改的初始化文件,使之立即生效,而不必注销并重新登录。例如我刚刚修改了 ~/.bashrc ,想让它立即生效,可以输入命令: source ~/.bashrc 或者 . ~/.bashrc。
eg:
[druihg@localhost /]$ vim ~/.bashrc // 我进入设置别名:alias c='clear',保存修改退出
[druihg@localhost /]$ c
bash: c: command not found
接着我另外打开一个终端,此时这个别名才可用。
如果想所有用户都可以使用别名,并且永久有效。请在 /etc/bashrc 最后添加设置,其他同上。
[root@localhost ~]# vim /etc/bashrc // 我进入设置别名:alias c='clear',保存修改退出
[root@localhost ~]# c
-bash: c: command not found
附:bashrc是环境变量的配置文件 /etc/bashrc和~/.bashrc 区别就在于一个是设置给全系统一个是设置给单用户使用.
// alias -- man page
alias [-p] [name[=value] ...]
Alias with no arguments or with the -p option prints the list of
aliases in the form alias name=value on standard output. When
arguments are supplied, 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.
For each name in the argument list for which no value is sup-
plied, the name and value of the alias is printed. Alias
returns true unless a name is given for which no alias has been
defined.
Note aliases are not expanded by default in non-interactive
shell, and it can be enabled by setting the expand_aliases shell
option using shopt.