Using Tab Autocomplete
Guide Overview
The purpose of this guide is to teach you how to use Tab Autocomplete to automatically complete paths and file names in a Linux terminal. The way it works is simple. All you do is press the Tab button on your keyboard, and the terminal automatically completes file names and paths. When you are used to using Tab Autocomplete, you will find using the terminal will be faster and you'll make less mistakes.
Tools Needed
- Linux
- Example 1
In this example I'll open a file in my home directory called Sustrans_glasgow_mapguide_Jan09.pdf using a pdf reader called Okular.
In my terminal I type the name of the application, okular, then the first letter of the file I want to open:okular S
..then press Tab on my keyboard, and the terminal automatically completes the name of the fileokular Sustrans_glasgow_mapguide_Jan09.pdf
This is because Sustrans_glasgow_mapguide_Jan09.pdf is the only file in my home directory that begins with the character "S" so Tab autocomplete knows that must be the file that I want. - Example 2
In this example I'll read a file called alternatives.log.1 at /var/log/alternatives.log.1, using cat
In my terminal I type:cat /v
Now I press Tab on my keyboard, and nothing happens. Why not? Because there is more than one directory beginning with the letter "v" in my root directory, so the terminal doesn't know which one I'm referring to. So I continue to type the next letter:cat /va
Now I press Tab on my keyboard again, and the terminal automatically completes the line:cat /var/
Because there is only one directory in my root directory beginning with "va" the terminal now knows which directory I want. See how it works?
So I continue and type the next letter of the path:cat /var/l
Now I press Tab on the keyboard, and again nothing happens. As you might have guessed, this is because there is more than one directory in my /var directory beginning with a lower case L.
Continuing to type the next letter:cat /var/lo
...I press Tab on the keyboard and again nothing happens, because there is more than one directory in /var beginning with "lo" so the terminal doesn't know which directory I want.
Typing the next lettercat /var/log
...the terminal now knows which directory I want when I press Tab:cat/var/log/
Typing the next character in the path:cat /var/log/a
..then pressing Tab, again nothing happens, because there is more than one file on /var/log beginning with the character "a"
Proceeding to type the next character:cat /var/log/al
... then pressing Tab, the terminal now partially completes the name of the file:cat /var/log/alternatives.log
There is more than one file starting with alternatives.log in /var/log/ and the terminal knows that I want one of these files, but I still have to tell it which one.
At this point, when the name of the path is almost complete, it would be just as well to type the rest of the path in manually.




Back to top







