- In this video,
I will tell you about command line completion.
Command line completion is another great feature
that is offered by all the current Linux shells.
So how does it work?
Well by using the tab key.
If you start typing a command and then you press tab,
then tab is going to try
to automatically complete the command.
And that works for commands,
for variables, as well as for file names.
And in case a tab key
doesn't give you anything to complete,
then you might have to press the tab key again
because sometimes there are just multiple options
and the shell doesn't know how to complete,
just do a tab, tab,
and you get an overview
of all the different options that exist.
Now in some cases you may find the best completion
doesn't work.
Then it's really recommended to install
the bash-completion package.
That will give you additional completion features
including completion that works for certain commands.
Let me demonstrate.
So to start with, I want to use user tab.
Oh, nothing is happening.
Well, that is because there are too many commands
starting with user.
So I'm using user tab tab, and there we go,
we have all the different options.
So I'm typing users and it executes the users commands.
Now, what is really amazing is if you use a command like IP.
IP is a pretty complex command,
we will investigate it in a little bit more detail
in the lesson about networking.
The IP command works with different arguments,
like IP address.
And there we go.
I'm completing to ip addr
and tab completion is showing me what I can do with ip addr.
So we have add and change and del and flush
and help and replace and show.
Let me just do a show and there we can see
how this bash completion even helps me
with arguments for some of the more complex commands.
And I would advise if you are going to work
with more complex commands,
give it a try and find out if bash completion
is working for these command arguments as well,
that will really make your life a lot easier.
Now it also works for variables.
So if I use echo $HI to refer to a variable,
I'm printing a dollar
and then the name of the variable.
Here, it's only the start of the variable.
I'm pressing tab.
And there we can see it's making it HIST.
I'm pressing tab twice again
and there we can see that there are different variables
including the HISTFILESIZE,
which is showing me that it's currently set to 1000.
So the actual length of the history file
is defined in a variable.
And of course you can use it on file names as well.
Let me create a ridiculously long file name.
There we go.
And do you really think it's complicated to work with it?
Of course not.
Just first two letters, then you press tab
and you can see the properties of this ridiculous file,
including the option that allows you
to remove this ridiculously long file.
And that's how you work with history.