Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Using bash auto completion features  (Read 2269 times)

0 Members and 1 Guest are viewing this topic.

vinayakk

  • Guest
Using bash auto completion features
« on: February 03, 2014, 01:58:14 pm »
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:

Code: [Select]
# yum install bash-completion
After installation exit the login shell / ssh session and log back again.

Use the following command to source completion code for bash:

Code: [Select]
# . /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

You should get more logical hints, try this:
# ifup [TAB][TAB]
eth0 eth0:0 eth0.bak lo

See - it's now suggesting (and completing) interface names instead of files in the current directory. Cool stuff!

 :)