【CentOS 7笔记31】,命令补全及别名#

shalow丿ovevim


命令补全及别名

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

命令补全

[root@localhost ~]# yum install -y bash-completion
	Loaded plugins: fastestmirror
	base                                                                        | 3.6 kB  00:00:00     
	epel/x86_64/metalink                                                        | 5.2 kB  00:00:00     
	epel                                                                        | 4.7 kB  00:00:00     
	extras                                                                      | 3.4 kB  00:00:00     
	updates                                                                     | 3.4 kB  00:00:00     
	(1/3): extras/7/x86_64/primary_db                                           | 130 kB  00:00:00     
	(2/3): epel/x86_64/updateinfo                                               | 848 kB  00:00:01     
	(3/3): epel/x86_64/primary_db                                               | 6.1 MB  00:00:10     
	Loading mirror speeds from cached hostfile
	 * epel: mirrors.ustc.edu.cn
	Resolving Dependencies
	--> Running transaction check
	---> Package bash-completion.noarch 1:2.1-6.el7 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	===================================================================================================
	 Package                      Arch                Version                  Repository         Size
	===================================================================================================
	Installing:
	 bash-completion              noarch              1:2.1-6.el7              base               85 k

	Transaction Summary
	===================================================================================================
	Install  1 Package

	Total download size: 85 k
	Installed size: 259 k
	Downloading packages:
	bash-completion-2.1-6.el7.noarch.rpm                                        |  85 kB  00:00:00     
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Installing : 1:bash-completion-2.1-6.el7.noarch                                              1/1 
	  Verifying  : 1:bash-completion-2.1-6.el7.noarch                                              1/1 

	Installed:
	  bash-completion.noarch 1:2.1-6.el7                                                               

	Complete!
[root@localhost ~]# systemctl restart network.service     #测试失败
[root@localhost ~]# reboot    #需重启

使用bash-completion包不只能够补全命令,还能够补全参数bash

别名

[root@localhost ~]# systemctl restart network.service     #从新测试
[root@localhost ~]# alias restart='systemctl restart network.service'
[root@localhost ~]# restart
[root@localhost ~]# 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 restart='systemctl restart network.service'
	alias rm='rm -i'
	alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'

各用户都有本身配置别名的文件~/.bashrcless

[root@localhost ~]# vi .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配置文件测试

[root@localhost ~]# cd /etc/profile.d
[root@localhost profile.d]# ls
	256term.csh         colorgrep.csh  colorls.sh  less.csh  vim.sh
	256term.sh          colorgrep.sh   lang.csh    less.sh   which2.csh
	bash_completion.sh  colorls.csh    lang.sh     vim.csh   which2.sh
相关文章
相关标签/搜索