shell脚本,alias别名命令用法。

[root@localhost ~]# alias
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# alias cp
alias cp='cp -i'
[root@localhost ~]# alias cls='clear'
[root@localhost ~]# 
[root@localhost ~]# alias cls
alias cls='clear'
[root@localhost ~]# alias
alias cls='clear'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# cls     #清屏了
这时增加临时别名,一重启就没有了。
如果要长久有效,需要在配置文件增加一下
如果在 .bashrc文件增加一条,或是在/etc/profile。我下面这种方法是在.bashrc文件下加的。
[root@localhost ~]# cls
bash: cls: 未找到命令...
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# vi  .bashrc 
[root@localhost ~]# cat .bashrc 
#  .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cp='cp -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

echo "hellow"
alias cls='clear'
[root@localhost ~]# 

[root@localhost ~]# alias cls   已经添加到配置文件了,为啥查看出现未找到,是因为没加载文件,加载文件有两种方式,一种是source .bashrc 另一种是 . .bashrc 
-bash: alias: cls: 未找到
[root@localhost ~]# source .bashrc         
hellow
[root@localhost ~]# alias cls
alias cls='clear'
[root@localhost ~]# 
[root@localhost ~]# alias
alias cls='clear'
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 ~]# unalias -a        临时清空所有别名
[root@localhost ~]# alias 
[root@localhost ~]# . .bashrc     一加载或是重启系统,所有别名就又存在了
hellow
[root@localhost ~]# alias
alias cls='clear'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@localhost ~]# 

[root@localhost ~]# cat .bashrc 
#  .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias cp='cp -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

echo "hellow"
alias cls='clear'
[root@localhost ~]# unalias cls   #unalias cls 删除指定别名为cls='clear'。
[root@localhost ~]# alias cls
-bash: alias: cls: 未找到
[root@localhost ~]# 

 

posted on 2016-09-05 12:38  王月波  阅读(12266)  评论(0编辑  收藏  举报

导航