1、查看系统中所有的别名
[root@centos79 ~]# alias
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@centos79 ~]#
2、临时设置别名。临时设置别名后,重新链接或重启系统,别名会被删除。
[root@centos79 network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
PROXY_METHOD=none
cat /etc/sysconfig/network-scripts/ifcfg-eth0 由于改命令比较长,现在给该命令做一下别名设置。
[root@centos79 network-scripts]# alias etho='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@centos79 network-scripts]#
[root@centos79 network-scripts]# alias ## 查看现有的别名
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias etho='cat /etc/sysconfig/network-scripts/ifcfg-eth0' ## 设置成功,别名中有记录
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@centos79 network-scripts]# etho ## 设置成功,可以使用。
DEVICE=eth0
BOOTPROTO=dhcp
3、永久设置别名。
3.1、先编辑 /etc/profile 文件。
[root@centos79 ~]# vim /etc/profile
在文件最后添加一行: alias etho='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
保存退出。
3.2、加载 /etc/profile 文件
[root@centos79 ~]# source /etc/profile
3.3、重新查看别名文件:
[root@centos79 ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias etho='cat /etc/sysconfig/network-scripts/ifcfg-eth0' ## 设置成功
alias fgrep='fgrep --color=auto'
[root@centos79 ~]#
3.4、检查是否成功
[root@centos79 ~]# etho
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
如何设置别名
最新推荐文章于 2024-05-14 19:33:47 发布