1.1alias查看和设置别名(全局)
查看linux命令的默认别名 [[email protected] ~]# 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‘
查看具体命令的别名 [[email protected] ~]# alias rm alias rm=‘rm -i‘ [[email protected] ~]# alias | grep rm alias rm=‘rm -i‘ [[email protected] ~]#
临时设置别名 [[email protected] ~]# alias rm=‘echo "do notuse rm command"‘ [[email protected] ~]# 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‘ [[email protected] ~]# rm -f 1.txt do not use rm command -f 1.txt [[email protected] ~]#
永久修改别名 [[email protected] ~]# unalias rm [email protected] ~]# rm rm: 缺少操作数 请尝试执行"rm --help"来获取更多信息。 法一:在/etc/profile系统全局变量的配置文件中或者存放别名、函数的/etc/bashrc中修改 [[email protected] ~]# 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
1.2单用户修改
在用户环境变量文件中修改,修改方法同上:~/.bashrc ~/.bash_profile 只对当前用户生效
1.3取消别名
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)
1.4实例:
设置net别名,执行net命令时,显示 /etc/sysconfig/network-scripts/ifcfg-eth0的内容
[[email protected] ~]# 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 [[email protected] ~]# net -bash: net: command not found [[email protected] ~]# alias net=‘cat/etc/sysconfig/network-scripts/ifcfg-eth0‘ [[email protected] ~]# alias net alias net=‘cat/etc/sysconfig/network-scripts/ifcfg-eth0‘ [[email protected] ~]# 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别名 [[email protected] ~]# unalias net [[email protected] ~]# net -bash: net: command not found
时间: 2024-10-06 06:08:03