Use tab to autocomplete commands in the command line

Updated: 12/31/2020 by Computer Hope
autocomplete dos tip

When at the MS-DOS, Windows command line or a Linux or Unix shell, typing in long file names or directories can become a burden. Use the Tab to autocomplete the names of directories and files while in the command line. Below are a few examples of how this can be done.

MS-DOS and Windows command line users

While at the prompt, typing in one or more letters a file or directory name contains will autocomplete the name in alphabetical order. For example, when at the C:\> prompt, type the command below.

cd p

After the command above is typed, instead of pressing the Enter, press the Tab. When you press the Tab, the first directory that begins with "p" will be automatically typed into the command. Continuing to press the Tab will cycle through all available directories, including the "Program Files" directory. This shortcut can be used any time you need to type a file name or directory in a command.


If you type one or more beginning letters for a file name or directory that does not exist in the current directory, the Tab key will not autocomplete.

Most Linux and Unix users

Depending on your variant of Linux or Unix and if you're remotely connecting to a Linux box changes how the Tab key autocompletes. However, below is a general run down on how this is commonly used in Linux. At the prompt in your home directory, type the command below.

cd p

Assuming your home directory has "public_ftp," "public_html," or another file or directory that begins with "p," you are shown all available files and directories. If you continue to type the next letter available, for example, "cd pu," completes the remaining of the file name or directory up to the point there's no conflict. If you had both directories mentioned earlier in the current directory, it would autocomplete up to "public_" because there are two directories beginning with "public_". Pressing the Tab again shows you the remaining available files beginning with "public_". If you wanted to type "public_html," add a "h" and press Tab to complete the directory name.

Additional information