标签:linux别名设置
查看linux命令的默认别名 [root@oldboyedu-36 ~]# alias 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@oldboyedu-36 ~]# alias rm alias rm=‘rm -i‘ [root@oldboyedu-36 ~]# alias | grep rm alias rm=‘rm -i‘ [root@oldboyedu-36 ~]#
临时设置别名 [root@oldboyedu-36 ~]# alias rm=‘echo "do notuse rm command"‘ [root@oldboyedu-36 ~]# alias alias l.=‘ls -d .* --color=auto‘ alias ll=‘ls -l --color=auto‘ alias ls=‘ls --color=auto‘ alias mv=‘mv -i‘ alias rm=‘echo "do not use rm command"‘ alias which=‘alias | /usr/bin/which --tty-only--read-alias --show-dot --show-tilde‘ [root@oldboyedu-36 ~]# rm -f 1.txt do not use rm command -f 1.txt [root@oldboyedu-36 ~]#
永久修改别名 [root@oldboyedu-36 ~]# unalias rm oot@oldboyedu-36 ~]# rm rm: 缺少操作数 请尝试执行"rm --help"来获取更多信息。 法一:在/etc/profile系统全局变量的配置文件中或者存放别名、函数的/etc/bashrc中修改 [root@oldboyedu-36 ~]# vim /etc/profile # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`/usr/bin/id-gn`" = "`/usr/bin/id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh ; do if [ -r"$i" ]; then if ["${-#*i}" != "$-" ]; then ."$i" else ."$i" >/dev/null 2>&1 fi fi done unset i unset -f pathmunge alias rm=‘rm -i‘ aliasrm=‘echo "do not use rm command"‘===最后一行追加上 source /etc/profile 法二:echo追加 echo ‘alias rm="echo do not use rmcommand"‘ >>/etc/profile(/etc/bashrc) source /etc/profile或者/etc/bashrc
在用户环境变量文件中修改,修改方法同上:~/.bashrc ~/.bash_profile 只对当前用户生效
unalias临时取消别名 -bash-4.1# alias rm alias rm=‘rm -i‘ -bash-4.1# unalias rm -bash-4.1# alias rm -bash: alias: rm: not found 永久取消:在/etc/profile或者/etc/bashrc配置文件中修改 方法同上设置别名;
\临时取消 cp /data/a.txt /tmp/(/tmp里面也有a.txt) 命令全路径屏蔽别名 /bin/cp /data/a.txt /tmp/(/tmp里面也有a.txt)
[root@oldboyedu-36-02 ~]# cat/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 HWADDR=00:0c:29:32:15:0e TYPE=Ethernet UUID=c13d35d3-f3e3-44c5-ae8a-39e0bab09185 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none IPADDR=10.0.0.200 NETMASK=255.255.255.0 GATEWAY=10.0.0.2 DNS1=10.0.0.2 USERCTL=no PEERDNS=yes IPV6INIT=no [root@oldboyedu-36-02 ~]# net -bash: net: command not found [root@oldboyedu-36-02 ~]# alias net=‘cat/etc/sysconfig/network-scripts/ifcfg-eth0‘ [root@oldboyedu-36-02 ~]# alias net alias net=‘cat/etc/sysconfig/network-scripts/ifcfg-eth0‘ [root@oldboyedu-36-02 ~]# net DEVICE=eth0 HWADDR=00:0c:29:32:15:0e TYPE=Ethernet UUID=c13d35d3-f3e3-44c5-ae8a-39e0bab09185 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=none IPADDR=10.0.0.200 NETMASK=255.255.255.0 GATEWAY=10.0.0.2 DNS1=10.0.0.2 USERCTL=no PEERDNS=yes IPV6INIT=no 取消net别名 [root@oldboyedu-36-02 ~]# unalias net [root@oldboyedu-36-02 ~]# net -bash: net: command not found
标签:linux别名设置
原文地址:http://dakaige517.blog.51cto.com/11912621/1922083