[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 ~]#