如何设置别名


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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值