3.6-变量别名 命令别名

命令别名将为公共命令及它们的参数创建别名,以尽可能减少录入工作。

1、查看系统已存在的公共命令别名
使用 alias -p 查看系统已存在的公共命令别名 活动列表

[root@hadoop ~]# alias -p
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'

2、使用alias创建命令别名

[root@hadoop ~]# alias li='ls -li'
[root@hadoop ~]# li
总用量 112
33574979 -rw-------. 1 root root  1419 6月  11 13:33 anaconda-ks.cfg
51251036 -rw-r--r--. 1 root root 22255 7月   8 13:53 customer.java
19751199 -rw-r--r--. 1 root root 20640 7月   8 13:53 date_dim.java
34855665 -rw-r--r--. 1 root root     0 7月   8 20:38 derby.log
51251011 -rw-r--r--. 1 root root 14215 7月   7 14:55 product.java
34318652 -rw-r--r--. 1 root root 11476 6月  14 10:26 QueryResult.java
51253816 -rw-r--r--. 1 root root 22853 7月   8 13:56 sales_order.java
51265292 drwxr-xr-x. 3 root root    42 6月  15 17:05 ${system:java.io.tmpdir}
33696874 -rw-------. 1 root root  1675 6月  11 16:40 y
33696875 -rw-r--r--. 1 root root   393 6月  11 16:40 y.pub

可以看到,定义了命令别名之后,可以使用别名。
注意:命令别名与本地环境变量相似,它们只对于定义范围内的shell进程有效:

[root@hadoop ~]# alias li='ls -li'
[root@hadoop ~]# bash
[root@hadoop ~]# li
bash: li: 未找到命令

3、如何使命令别名全局有效
在启动新的交互式shell时,bash shell 始终会读取 H O M E / . b a s h r c 启 动 文 件 , 可 以 将 别 名 放 入 HOME/.bashrc启动文件,可以将别名放入 HOME/.bashrcHOME/.bashrc

[root@hadoop ~]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

alias li='ls -li'
[root@hadoop ~]# bash
[root@hadoop ~]# li
总用量 112
33574979 -rw-------. 1 root root  1419 6月  11 13:33 anaconda-ks.cfg
51251036 -rw-r--r--. 1 root root 22255 7月   8 13:53 customer.java
19751199 -rw-r--r--. 1 root root 20640 7月   8 13:53 date_dim.java
34855665 -rw-r--r--. 1 root root     0 7月   8 20:38 derby.log
51251011 -rw-r--r--. 1 root root 14215 7月   7 14:55 product.java
34318652 -rw-r--r--. 1 root root 11476 6月  14 10:26 QueryResult.java
51253816 -rw-r--r--. 1 root root 22853 7月   8 13:56 sales_order.java
51265292 drwxr-xr-x. 3 root root    42 6月  15 17:05 ${system:java.io.tmpdir}
33696874 -rw-------. 1 root root  1675 6月  11 16:40 y
33696875 -rw-r--r--. 1 root root   393 6月  11 16:40 y.pub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值