linux的别名(alias/unalias)

 

linux中有别名时先找的别名后找命令文件


临时创建是直接用alias

[root@localhost ~]# alias ls=pwd

[root@localhost ~]# ls

/root

其中alias定义的别名只是临时的,只针对当前会话可用.切换到另一个终端标签或新建另一个终端,定义的别名不可用.

 

永久创建别名:将别名写入家目录的.bashrc文件,source一下生效。

注意:在~/.bashrc  修改当前用户家目录里的.bashrc, 仅对当前用户生效,是个人配置文件.

在/etc/bashrc里修改则对所有用户生效,是全局配置文件

[root@localhost ~]# vim .bashrc 

# .bashrc

# User specific aliases and functions

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

alias g=ls

# Source global definitions

if [ -f /etc/bashrc ]; then

        . /etc/bashrc

fi

[root@localhost ~]# . .bashrc 

[root@localhost ~]# g

 

anaconda-ks.cfg  initial-setup-ks.cfg

 

查看系统定义了哪些别名,直接alias:

[root@localhost ~]# alias

alias cp='cp -i'

alias egrep='egrep --color=auto'

alias fgrep='fgrep --color=auto'

alias g='ls'

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'

 

查看具体别名:which+别名

[root@localhost ~]# which ls

alias ls='pwd'

/usr/bin/pwd


取消别名方法:命令行前加 (此为单次取消别名)

[root@localhost ~]# ls

anaconda-ks.cfg  initial-setup-ks.cfg

取消别名也可直接取命令对应的文件: /bin/ls ..

[root@localhost ~]# /usr/bin/ls 

anaconda-ks.cfg  initial-setup-ks.cfg

或直接取消别名:unalias+别名(此为临时取消别名)

[root@localhost ~]# unalias ls

[root@localhost ~]# ls

anaconda-ks.cfg  initial-setup-ks.cfg

 


原文地址:https://www.cnblogs.com/lbg-database/p/10109987.html