3.2 Bash Completion
Bash completion makes it easier to use commands. When used to navigate, you do not need to type full names of directories and or files.
To install bash completion (when it is missing on your machine), you can use the following command: dnf (we will revisit dnf later). Your machine comes installed with bash-completion, so you do not need to do anything for now. However, during the exam this is not guaranteed to be installed.
dnf install bash-completion
Using Bash Completion
Let’s say we want to make a copy of the file onthegenealogyofmorality which is a uselessly long and uncomfortable file name.
We can use the following command:
cp /media/onthegenealogyofmorality /root/.
However, this time do not copy the command or type it; we will use bash completion using the tab button. This will save us time and frustration. Perform the command as follows:
cp /media/on[press tab here] /root/.
By typing only two letters, we were able to autocomplete the last part of the file name. This works with anything on the command line.
When pressing tab twice, bash will list all potential outcomes. For example:
type lv and press tab twice.
lv [tab][tab]
[fons@rhcsa media]$ lv
lvchange lvcreate lvextend lvmconfig lvmdump lvmsadc lvreduce lvrename lvs
lvconvert lvdisplay lvm lvmdiskscan lvmpolld lvmsar lvremove lvresize lvscan
And it gives you a list of all commands that start with lv.
Some core linux commands can actualy also autocomplete with tab or list all options with 2* tab. This is a very usefull tool during the exam; it prevents typing errors and or confusion with commands.
Try to use as much tab completion during the practices from now on!