linux别名alias
alias 命令
alias 命令:
介绍:输出和设置系统别名
格式:alias command='command +[option]'
用法:
- 直接使用 alias :列出所有别名 
- alias ls='/bin/ls' :设置别名 
[root@localhost ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhost ~]# alias ls='ls --color=auto'
[root@localhost ~]# alias a='a+b'等号间不能有空格
[root@localhost ~]# alias a = 'a+b'
alias a='a+b'
-bash: alias: =: 未找到
-bash: alias: a+b: 未找到但是这样的设置只在当前控制台有效,可以在两个地方修改使其一直有效:
- 本用户家目录下的 .bashrc 文件中,这个只会在本用户登陆时有效 
- /etc/profile 文件,所有用户都会生效 
[root@localhost ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
[root@localhost ~]# tail -3 /etc/profile
unset i
unset -f pathmunge
alias a="a+b"修改后要使用source /etc/profile 或source .bashrc 才能生效。
最后更新于
这有帮助吗?