How to use filename completion in Linux?

Filename completion is the feature of a Unix shell such as bash, csh, tcsh, ksh, etc which allows a user to type the name of a file or directory partially and press a key to fill out the rest. You need to type only enough of a file or directory name to make it unique, and then press the Esc key twice(in bash) or Tab key once to fill in the rest.

Most of the Linux systems offer only a command-line interface so it requires knowledge of commands to interact with the underlying operating system. Sometimes you need to edit a file or move to a directory that is hard to remember in this situation filename completion feature can be very helpful.

The filename completion feature can also make you more productive as it requires less typing and makes things faster.

Please note a few things –

  • The file completion feature doesn’t work in the sh shell.
  • To use filename completion in csh first, you need to enter set filec then use Esc once to fill out that name while typing something in your terminal.
  • In the bash or tcsh shell, you need to press the Tab once or Esc twice to complete a filename.

Examples of using filename completion in Linux

If you don’t know which shell you are using then use the given command in your terminal to check the default shell.

echo $SHELL

This will display the output some like given in the image below.

check shell

Now let’s see the example of how to use the filename completion (also known as tab completion) in Linux. Here I am using bash you can see the files and directories in my home directory.

home dir

Suppose I want to move to the Downloads directory then I will use –

cd Download

OR, by using the filename completion feature you only need to type the directory name partially then press the Tab key or Esc key twice fill out the rest. Finally, you need to press the enter to execute the given command.

cd Dow

filename completion bash

Now, what if I enter only D instead of Dow? This is not enough to identify the Download directory uniquely there are three directories in my home directory that start with the letter D i.e. Desktop, Downloads, and Documents. Similarly Do is also not sufficient because there are two directories that start with the letters Do i.e. Downloads and Documents. So you have to type Dow to identify the Downloads directory uniquely.

You can type D and then press Tab twice or Esc = to see the names of files and directories that start with the letter D.

For example –

cd D

filename suggestion in bash

Now from the given suggestion, you can choose the directory where you want to move.

As discussed earlier sometimes file or directory names are harder to remember in this case filename completion can help you.

For example, I have a directory named xVST_2_5_1_x64-linux-dynamic in my home directory. Instead of typing it manually, you need to type a few initial letters of it and then press the Tab to auto-fill the name.

Finally, you can press the enter to execute the command.

Ok that all for now. I hope you understand how to use filename completion in Linux. This is not specific to an operating system it is a shell built-in feature so you can use it on any system that uses a Unix shell.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version