< Automatic file name completion - 1.0 >

Automatic file name completion is one of the most useful features of the Linux command line. You don't have to type or even remember long file names at the Linux CLI - just press the Tab key and the shell does the typing for you!

Author: Nana Långstedt < nana.langstedt at gmail.com >
tuXfile created: 3 March 2003
Last modified: 22 September 2005


back to

< How file name completion works >

Working at the Linux command line requires a lot of typing. It would get very frustrating with long commands and file names, but luckily your Tab key can make your life a lot easier.

You have to type only the beginning of a command, directory, or a file name, hit the Tab key and the shell completes the rest! For example, if you want to view a file called unBELIEVABLY-LongANDstupid.FileName.txt, all you have to type is something like:
$ less un
and hit the Tab key. The rest of the monster file name is completed automatically and you don't necessarily have to even remember the whole file name! It's that simple.

< Files starting with same letters >

There may be several files that start with the same letters but have different endings. How the shell behaves when you press the Tab key in this case, may differ depending on the shell and how it's configured. Usually with a default bash configuration, when you've typed the first letters of a file name and hit the Tab key, the shell completes as much as it can and beeps. When you press the Tab key again, the shell shows you all the alternatives. Sometimes you'll have to hit Tab twice before it shows you the alternatives.

Now you can either type the whole file name, or type a couple more letters and hit Tab again.

We'll have an example: suppose you have files called unBELIEVABLY-LongANDstupid.FileName.txt and unBELIEVABLEfile.txt and you want to view the other file. Again, you try typing
$ less un
and hit the Tab key. However, now the shell completes as much as it can and beeps:
$ less unBELIEVABL

Now if you hit the Tab key again, either once or twice, the shell shows you the alternatives:

$ less unBELIEVABL
unBELIEVABLY-LongANDstupid.FileName.txt unBELIEVABLEfile.txt

Now you can type
and hit Tab again. Now the shell knows which file you mean and completes the rest.

The shell you are using may behave a bit differently, so go ahead and experiment with your command line for a while. Pretty quickly you'll get the hang of this feature, you'll start using it all the time, and you won't survive without file name completion anymore!

< What can be completed >

You can complete anything: commands, program names, directories, and file names. Just try it!

For example, to issue the command umount /mnt/floppy, you can first type um, hit Tab, then type /mn, hit Tab, then type f, hit Tab, and that's it!

< What next? >

Related tuXfiles

Linux help > The shell and command line > Automatic file name completion

Copyright © 2001 - 2011 Nana Långstedt