8.3 命令补全和别名

命令补全及别名目录概要

  • tab键,敲一下,敲两下
  • 参数补全,安装 bash-completion
  • alias别名给命令从新起个名字
  • 各用户都有本身配置别名的文件 ~/.bashrc
  • ls /etc/profile.d/
  • 自定义的alias 放到 ~/.bashrc

命令补全

  • 在centos6中,命令补全仅支持命令自己,参数是不能补全的
  • 在centos7中,支持命令的参数补全
    • 须要安装包bash-completion——>yum install -y bash-completion
    • 安装完成后,须要重启下虚拟机(reboot命令)才可生效
    [root@hf-01 ~]# rpm -qa bash-completion        //查看包是否安装完成
    bash-completion-2.1-6.el7.noarch
    • 再来测试,会看到一条命令行均可以补全

alias别名

    1. 如果命令较长,能够设置别名
[root@hf-01 ~]# systemctl restart network.service        //重启网络服务
[root@hf-01 ~]# alias restartnet='systemctl restart network.service'
[root@hf-01 ~]# restartnet        //设置别名后,重启网络服务
[root@hf-01 ~]#
- 取消别名unalias
    - 在取消别名后,在输入别名,就会提示未找到命令
[root@hf-01 profile.d]# unalias restartnet
[root@hf-01 profile.d]# restartnet
-bash: restartnet: 未找到命令
[root@hf-01 profile.d]#
    1. 直接输入alias 会看到系统中全部的别名(包括本身自定义的alias)
[root@hf-01 ~]# 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 restarnet='systemctl restart network.service'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@hf-01 ~]#
    1. alias存放位置
    • 第一个是存放在用户家目录下的 .bashrc 文件中
    • 第二个是存放在 /etc/profile.d 目录下的 colorls.sh 和 colorgrep.sh 脚本中定义的
相关文章
相关标签/搜索