用Linux自动补全怎么补全命令?

秩名发表于 2020-03-25 18:02次浏览

用Linux自动补全怎么补全命令?git、Docker等命令要补全时该怎么进行?Linux自动补全可以帮助你解决这个问题,下面我们一起学习一下,怎么用Linux自动补全怎么补全命令?

什么是命令自动补全

在 Linux 命令行中,当输入字符后,按Tab 键,Shell 就会列出以这些字符开头的所有可用命令,如果只有一个命令匹配到,按一次 Tab 键就自动将这个命令补全。

如果输入pass,此时按 Tab 键,因为以pass开头的命令只有passwd这个命令, Shell 就会自动补全 passwd 命令。

另外如果输入的字符匹配多个命令则会列出所有可用的命令,比如,如果输入do,此时按 Tab 键 Shell 就会自列出可用的命令。

[root@node2 ~]# do

do docker-containerd-shim dockerd done

docker docker-containerd-shim-current dockerd-current

docker-containerd docker-ctr-current docker-storage-setup

docker-containerd-current docker-current domainname

但是系统自带的命令补全功能有限,自动补全功能仅限于命令和文件名。

可以安装 Bash 命令补全增强软件包 bash-completion来实现更多命令的补全。

bash-completion的安装

以Centos为例

[root@node1 ~]# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

直接通过yum命令安装

yum install bash-completion

bash-completion版本信息

[root@node1 completions]# rpm -qi bash-completion

Name : bash-completion

Epoch : 1

Version : 2.1

Release : 6.el7

Architecture: noarch

Install Date: Thu 19 Mar 2020 07:59:19 AM CST

Group : Unspecified

Size : 264934

License : GPLv2+

Signature : RSA/SHA256, Fri 04 Jul 2014 08:47:01 AM CST, Key ID 24c6a8a7f4a80eb5

Source RPM : bash-completion-2.1-6.el7.src.rpm

Build Date : Tue 10 Jun 2014 08:05:27 AM CST

Build Host : worker1.bsys.centos.org

Relocations : (not relocatable)

Packager : CentOS BuildSystem

Vendor : CentOS

URL : http://bash-completion.alioth.debian.org/

Summary : Programmable completion for Bash

Description :

bash-completion is a collection of shell functions that take advantage

of the programmable completion feature of bash.

配置命令补全

source /usr/share/bash-completion/bash_completion

命令补全的脚本存放在/usr/share/bash-completion/completions/目录,可以在这个目录查看支持增强补全功能的命令。

再试试输入docker命令后按tab键:

[root@node1 completions]# docker

build diff history inspect logs port restart search stats top wait

commit events image kill network ps rm secret stop unpause

container exec images load node pull rmi service swarm update

cp export import login pause push run stack system version

create help info logout plugin rename save start tag volume

[root@node1 completions]# docker

可以看到后续可用命令的提示,妈妈再也不用担心我记不住命令了。

同样对于kubenetes也可以实现命令的自动补全和提示:

[root@node1 ~]# kubectl

annotate certificate cordon drain get port-forward run uncordon

api-versions cluster-info cp edit label proxy scale version

apply completion create exec logs replace set

attach config delete explain options rolling-update taint

autoscale convert describe expose patch rollout top

[root@node1 ~]# kubectl

git的命令补全

如果是在安装bash-completion之后安装git是不能自动命令补全,需要手动进行一些配置。

git安装之后文档里会有git-completion.bash文件

[root@node1 bash-completion]# find / -name git-completion*

/usr/share/doc/git-1.8.3.1/contrib/completion/git-completion.bash

/usr/share/doc/git-1.8.3.1/contrib/completion/git-completion.tcsh

/usr/share/doc/git-1.8.3.1/contrib/completion/git-completion.zsh

/usr/share/bash-completion/completions/git-completion.bash

/usr/share/git-core/contrib/completion/git-completion.tcsh

[root@node1 bash-completion]#

安装完git之后重新source一下bash-completion

source /usr/share/bash-completion/bash_completion

看看配置之后的效果

[root@node3 ~]# git

add cherry difftool init reflog show

am cherry-pick fetch log relink show-branch

annotate clean filter-branch merge remote stage

apply clone format-patch mergetool repack stash

archive column fsck mv replace status

bisect commit gc name-rev request-pull submodule

blame config get-tar-commit-id notes reset subtree

branch credential grep pull revert tag

bundle describe help push rm whatchanged

checkout diff imap-send rebase shortlog

[root@node3 ~]# git

linux 文件名 自动补全,用Linux自动补全怎么补全命令?相关推荐

  1. Linux文件名包含小括号处理

    Linux文件名包含小括号处理 Linux环境中,解压zip文件后发现文件名包含小括号 ( ) , [root@my-workspace my]# ls -l On_Time_Reporting_Ca ...

  2. LINUX检测服务并自动运行,一种Linux下的开机自动检测硬件信息的方法与流程

    技术领域本发明涉及服务器开机检测技术,具体的说是一种Linux下的开机自动检测硬件信息的方法. 背景技术: 服务器产品研发初期,产品多为工程样本,问题很多,这些问题中硬件问题占较大部分.在工程验证测试 ...

  3. Oracle自动备份脚本(Linux)

    脚本编写 之前我在Linux Crontab有提到第一个脚本 http://blog.csdn.net/yangshangwei/article/details/52452599#t30 第一个脚本 ...

  4. linux自动挂载文件修复,Linux文件系统管理 开机自动挂载及fstab文件修复

    概述 开机自动挂载及fstab文件修复 开机自动挂载 实现开机后自动挂载,就需要修改系统的自动挂载文件 /etc/fstab.因为系统就是依赖这个文件决定启动时加载的文件系统的. 通过vi 打开/et ...

  5. 自动驾驶QNX,Linux,Autosar概述

    自动驾驶QNX,Linux,Autosar概述 QNX是一个分布式.嵌入式.可规模扩展的实时操作系统.遵循POSIX.1 (程序接口)和POSIX.2 (Shell和工具).部分遵循POSIX.1b( ...

  6. linux 多路径重启,(linux多路径连接iScsi存储重启自动连接.docx

    (linux多路径连接iScsi存储重启自动连接 RHEL系统带有iSCSI initiator软件,下面描述如何配置iSCSI Initiator实现对ISCSI卷的访问Linux iscsi 介绍 ...

  7. linux格式化大于2t硬盘分区,linux下大于2tb硬盘格式化及挂载,linux下大于2t的分区方法,linux gpt分区表 管理 自动挂载分区...

    linux下大于2tb硬盘格式化及挂载,linux下大于2t的分区方法,linux gpt分区表 管理 自动挂载分区 (7页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找 ...

  8. 在linux上一行代码不用写实现自动采集+hadoop分词

    在linux上一行代码不用写实现自动采集+hadoop分词 将下面的shell脚本保存成到xxx.sh,然后执行即可 cd /opt/hadoop mkdir spider wget -O spide ...

  9. linux 关机时卸载sd,Linux下U盘SD卡的自动挂载和卸载

    以下内容主体转自如下两篇博客: http://blog.sina.com.cn/s/blog_557366df0100nk7r.html http://blog.csdn.net/xdw1985829 ...

  10. linux磁盘符变化autofs,Linux基础教程学习笔记之Autofs自动挂载

    Linux基础教程学习笔记之Autofs自动挂载 Autofs自动挂载: yum -y install autofs vim /etc/auto.master  在文件中添加下面行 /home/gue ...

最新文章

  1. [裴礼文数学分析中的典型问题与方法习题参考解答]4.3.23
  2. 《现代前端技术解析》读后鬼扯
  3. 排查链接是否失效_如何进行移动站点流量排查?
  4. 火山引擎端云一体化服务:打造面向体验的视频云
  5. [转]写好shell脚本的13个技巧
  6. 全志r11_全志R328 Demo开发板;全志R333开发板/核心板;全志R11开发板/核心板;全志R16开发板/方案设计...
  7. HTML中放置CSS的三种方式和CSS选择器
  8. wpf中显示HTML
  9. windows下安装cygwin以及SeismicUnix在cygwin下的安装(windows下安装linux环境,非虚拟机、非双系统)
  10. 通过binlog恢复mysql备份之前的数据
  11. OmniGraffle 7 Pro全新推出!V7.18.3(204.9.0)正式版 支持M1
  12. python 操作excel表格
  13. 19.Java 数据库编程
  14. dw怎么写html,dw怎么写html
  15. 第1.5 章 elasticsearch备份过程记录
  16. 印象笔记不同步问题的解决方法
  17. android 自动弹起键盘
  18. Win10 虚拟桌面的使用
  19. Synchronized锁的使用
  20. Houdini_grass_sim (关于植物结算)

热门文章

  1. HDR(高动态范围)
  2. 怎么下载Windows图片和传真查看器
  3. 集合竞价如何买入_散户可以在集合竞价时买入股票吗?
  4. SpringBoot防止大量请求攻击
  5. axure中继器求和_中继器使用场景(二):购物车金额实时求和
  6. kindle自定义屏保之自定义字帖
  7. 历时一年,我的著作《第一行代码——Android》已出版!
  8. 给pdf添加导航目录
  9. toMap函数 java.lang.IllegalStateException: Duplicate key 123 (attempted merging values 123 and 124)
  10. GC回收算法--当女友跟你提分手!