Skip to content

Lesson 8: Using tab completion

Using tab completion will save you a lot of time when inputting commands by reducing the number of keystrokes needed by the user. If you type enough characters that uniquely identify the name of a file, directory or program and press tab, Linux will auto-complete the rest. For example, if you type 'tou' and then press tab, Linux should auto-complete the word to touch (this is a command which we will learn more about on the next page).

In the above example, tab completion will occur because there are no other Linux commands on the users PATH (more on that later) that start with 'tou'. If pressing tab doesn't do anything, then you have not have typed enough characters to uniquely identify the target. In this case pressing tab twice will show you all possible completions. This trick can save you a LOT of typing!

Note

Tab completion will make your life easier and make you more productive!

Command History

Another great time-saver is that Linux stores a list of all the commands that you have typed in each login session. You can access this list by using the history command or more simply by using the up and down arrows to access anything from your history.

Additionally, pressing Ctrl-r (that is holding the Ctrl key and pressing r) will start matching the last command you have executed within your command history from the characters you have entered. For example just typing ls will match all directory listing commands previously executed. In the below example, the last command ran was ls -l /home:

[learner learning_linux]$ (reverse-i-search)`ls': ls -l /home

Pressing enter will execute the matched command.