For any Linux professional user, the command line is an essential and ultra powerful tool. In this lecture 1
I'll teach you how to be really efficient when using the terminal. 2
The most important advice I could give you is to use the TAB key for auto-completion. 3
This is something you cannot live without, it will not only save you so much time at the Linux command 4
line, but it will keep you from making mistakes as well. 5
TAB is a feature supported by Bash and other shells as well. 6
If you have to remember only one shortcut, 7
this should be the chosen one. 8
How it works is really simple! When typing at the Linux command line, just use TAB to autocomplete 9
commands, filenames or folder names. 10
To use this feature type the first few letters of the command you want to run or the filename you 11
work with, followed by TAB. Bash will scan the current directory, as well as all other directories 12
in the search path for matches to that name. 13
If a single match is found, Bash will automatically complete the filename for you; if multiple matches are found, 14
you have to press the tab key twice and it will show you all results and you should continue typing 15
until there is only one match. 16
Let's see some practical examples! In my terminal 17
I write the letters i 18
f 19
s 20
And press tab on my keyboard. 21
The shell has automatically completed the command for me! Note that the letters ifc uniquely identifies 22
the ifconfig command and that's why it has automatically completed it. 23
But if I write if and press tab nothing happens! Do you know way? Because there is more than one command 24
beginning with the letters i and f and the shell doesn't know which one I'm referring to. 25
What I can do is press tab twice and it will display all available commands that start with i and f. 26
And there are two. 27
Then I can continue typing until it can uniquely identify the command and autocomplete it. Let's see 28
another example! Tab is used to autocomplete, both the commands and the files or directories. 29
I'm writing cat, a white space a forward slash and e and I'm pressing tab. It has completed the etc directory 30
from the root directory, which is forward slash because there is only one directory that starts with the 31
letter e and that's etc. 32
I continue and type the letters p, a and press tab. 33
Nothing happens because there is more than one file or directory beginning with pa and the shell 34
doesn't know which file or directly I want; but if I press tab two times it will display all the 35
files and directories that start with pa and r in the /etc directory and there are five. 36
I'm typing the next letter, which is s and pressing tab. 37
Now the shell knows what I want and autocomplete of the entire file name. By the way the cat 38
command displays the entire contents of the file at the terminal. 39
Now it's time to tell you something really important, something that, in my opinion is the key to 40
not make serious mistakes while working in the Linux terminal. If TAB does not complete automatically 41
a command or a filename when it should, then there is a mistake. 42
Do not continue writing the command or the file name, but stop and analyze what you have done up to that 43
point. 44
Tab doesn't complete because somehow, somewhere there's an error. 45
For example, let's suppose that by mistake I'm writing a whitespace before the p letter like this. 46
I'm hitting tab and nothing happens. 47
It would be a mistake on my part to try to write the file name manually. 48
I've got two errors! What I should do is analyze the command line and try to find the error, like 49
this whitespace here. 50
I'm removing it and then hitting tab and it completes the filename. 51
Another common mistake is to try to write the file and directory names manually instead of using tab. 52
Let's 53
suppose I want to remove a file in /var/log 54
directory. 55
Like this: rm and the full path to that file so /var 56
/log and the file. 57
a random file, 58
it doesn't matter, I won't remove it anyway. 59
Don't focus on rm command, which is used to remove files and the directories, because we have plenty 60
of time to talk about it later in the course. Instead of using tab auto completion, like I actually did, 61
I write to the path manually. 62
And there's the chance that by mistake I'll write a whitespace before the filename like this. 63
The effect will be that the rm command will consider that two arguments were given. 64
/var/log and the file and we'll try to remove them both. 65
So instead of removing that specific file, you could remove the entire /var/log directory, 66
which will break your entire system. 67
Such a mistake is avoided if you always use tab completion. 68
I hope that this lecture has provided you with a good understanding of how tab completion works and 69
how to properly use it.