Summary
Linux is full of shortcuts, you just need to know what they are or where to look for them. Tab completion is one of those features that is great at its simplest, with hidden power that you may be unaware of.
What Is Tab Completion?
Tab completion is a fantastic little feature that adds convenience, saves time, and can even help to prevent mistakes. It’s one of the oldest forms of auto-complete in computing: press Tab on a command line and you’ll see a command or filename completed (if unambiguous) or a set of possible options (if ambiguous).
Here are some examples of how tab completion works.
Tab completion is a feature of your shell, and this article focuses on two of the most used: bash and zsh. Completion is highly configurable, and features vary between systems.
Type the first few letters of a command (tryaprormkd), then press Tab. If your shell finds only a single command beginning with those letters, it will auto-complete it by printing the remaining letters. Now, you can press Enter to run the command or continue typing to supply more arguments.

If your initial text matches more than one command, their names will print to the screen. Here’s an example showing the text rm followed by a Tab:
You can continue to type and press Tab to refine the list until it is unambiguous or you’ve typed your full command.

Tab completion also works for filenames that you supply as arguments. For example, you may typels /ufollowed by Tab and your shell should complete it tols /usr/. This makes it much faster to type longer paths, and it’s also far less error-prone.
This level of tab completion alone will transform your Linux experience. When I first learned about tab completion, it felt like magic, and I don’t think I could live without the feature today. But, as I discovered recently, tab completion offers so much more than just command and filename completion.

Tab Completion Is So Much More
For a start, try tab completion with a command like cd, in a directory containing both files and folders. You should notice thatcd {start-of-directory}, then Tab, auto-completes the directory name, butcd {start-of-file}, then Tab, does not. The shell is clever enough to recognize thatcd’s argument should be a path to a directory, not a file, so it auto-completes the former, but not the latter.
Your shell should include a trailing slash after completing a directory, even if you only need to supply the directory’s name. This lets you quickly tab-complete an entire path without having to stop and type each / between directory names.

By showing all matches when there are more than one, your shell can help you narrow down whatever you’re trying to type. But some shells take this further. For example, in zsh, on macOS, when I typels Dofollowed by Tab, my shell prints two matches, Documents and Downloads:
If I now press Tab again, it completes tols Documents/, and pressing Tab further times cycles betweenls Documents/andls Downloads/. Note that this only happens when there is ambiguity. If you typels Documents/, then press Tab, the auto-complete will print all files inside Documents rather than cycling to the Downloads directory.

Addbind TAB:menu-completeto your ~/.bashrc orTAB:menu-completeto your ~/.inputrc if you want this behavior.
To accept a completion when cycling, but continue tab completing—e.g. for a long path—you can press / at the end of the directory you want to select.

Tab completion can also handle options supported by the command you’ve typed. For example, try typingmkdir -followed by a Tab. Again, the results will depend on your environment, but either way you should be able to see a list of options that mkdir supports:
On macOS, my shell shows single-letter options for mkdir, like-mand-p. Alongside each, it shows usage text that explains what the option does. On Ubuntu, my shell shows long options. It doesn’t print any usage info, but long options are more self-documenting anyway.

The git Command Takes Completion to the Next Step
Auto-completing options were a real eye-opener for me. I was so used to using man or a –help option to show command usage, I had no idea my shell could do a lot of the work for me. But it was the git command that really showed me the true power of auto-complete, and it’s transformed the way I work since.
The git program is incredibly self-aware, so its auto-complete options effectively provide an alternative interface. you may start by exploringall of git’s subcommandsby typinggitfollowed by a tab:
But git auto-complete shows its full power when working in a git repository. Let’s say you’ve made a change to a single local file, like a README.md:
Now typegit add, then a Tab, and your shell should transform that intogit add README.md. The git program has recognized that the add subcommand can be followed by a list of filenames to add them to the current commit. It’s aware that it only makes sense to add files that have actually changed, so it can auto-complete the full name of the only file that needs to be added.
Likewise, once you’ve added a file,git committhen Tab will auto-complete its name, along with other files that you can commit immediately, including files you haven’t yet added:
This completion even takes arguments into account. For example, once you’ve added a file to the index, you can unstage it using git restore –staged, as git status explains. At this point,git restore –stagedfollowed by a Tab will show just README.md, the only file that is staged:
Tab completion is so useful that you’ll find yourself using it all the time once you’ve discovered it. But it always pays to be curious: keep pressing Tab at different points in your command chain, and you’ll learn exactly how powerful this feature can be.