Autocomplete is nothing but a collection of various hacks that specify how arguments are to be completed by Readline using complete
built-in. By default, this feature is turned on many Linux distributions such as Debian Linux, Ubuntu Linux and more. However, this feature is not installed on RHEL based Linux distributions.
Installation
First, turn on the EPEL repo and type the following yum
command to install bash-completion package:#
yum install bash-completion
Sample outputs:
Loaded plugins: product-id, rhnplugin, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. This system is receiving updates from RHN Classic or RHN Satellite. Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package bash-completion.noarch 1:1.3-5.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: bash-completion noarch 1:1.3-5.el6 epel 215 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 215 k Installed size: 576 k Is this ok [y/N]: y Downloading Packages: bash-completion-1.3-5.el6.noarch.rpm | 215 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : 1:bash-completion-1.3-5.el6.noarch 1/1 Verifying : 1:bash-completion-1.3-5.el6.noarch 1/1 Installed: bash-completion.noarch 1:1.3-5.el6 Complete!
How do I use bash Autocomplete feature?
Then exits a login shell / ssh session and log back in using the following command:#
logout
Open a terminal or log in using ssh:$
ssh nixcraft@server1.cyberciti.biz
Alternatively, use the following command to source completion code for bash:$
. /etc/bash_completion
OR$
source /etc/bash_completion
Usage examples
You need to simply press [TAB] key. The syntax is:
command [TAB] command arg[TAB][TAB] man da[TAB]
rpm usage
Type the following command (type rpm -qi ph followed by [TAB]):
$ rpm -qi ph[TAB][TAB] php php-cli php-common php-devel php-imap
yum usage
Type the following command:
$ yum [TAB][TAB] --assumeyes --enableplugin list search --cacheonly --enablerepo makecache --setopt check --errorlevel --nogpgcheck shell check-update --exclude --noplugins --showduplicates clean groupinfo --obsoletes --skip-broken --color groupinstall provides --tolerant --config grouplist --quiet update --debuglevel groupremove --randomwait upgrade deplist help reinstall --verbose --disableexcludes --help --releasever version --disableplugin history remove --version --disablerepo info repolist distro-sync install resolvedep downgrade --installroot --rpmverbosity
To search a package called lsof:$
yum se[TAB] lsof
Or search and install on fly:
# yum in[TAB] ls[TAB] lshell.noarch lslk-debuginfo.x86_64 lsscsi-debuginfo.x86_64 lshw-gui.x86_64 lslk.x86_64 lsscsi.x86_64 lshw.x86_64 lsof-debuginfo.x86_64 lsyncd.x86_64
cryptsetup usage
Linux Unified Key Setup-on-disk-format (LUKS) allows you to encrypt whole disks and you can
use cryptsetup command to mount or remount encrypted partition:cryptsetup
[TAB] luksOpen /dev/md[TAB]
Sample outputs:
A list of all commands supported by Autocomplete feature
Type the following command:$
cd /etc/bash_completion.d
$ ls
Sample outputs:
autoconf gpg2 ntpdate shadow automake gzip open-iscsi smartctl bash-builtins iconv openssl sqlite3 bind-utils iftop perl ssh brctl ifupdown pkg-config strace bzip2 info pm-utils subscription-manager chkconfig ipmitool postfix tar configure iproute2 procps tcpdump coreutils iptables python util-linux cpio lsof quota-tools wireless-tools crontab lvm redefine_filedir xmllint cryptsetup lzma rfkill xmlwf dd make rpm xz dhclient man rsync yum.bash e2fsprogs mdadm scl.bash yum-utils.bash findutils module-init-tools service getent net-tools sh