You do not have to type a file or command name in full: Tab completes it and shows along the way whether such a name exists.
Tab asks the shell to complete the word under the cursor — this is called completion. At the start of the line the shell looks among command names, further on among file and directory names.
If one name fits, the shell completes all of it. If several fit, it completes the shared part and stops. If Tab added nothing, the next Tab lists the matching names below the line. If nothing fits, the line stays the same and no list appears.
A completed name exists, so Tab also checks your path. If Tab will not complete a file you know is there, look for a typo in the part you have already typed.
The directory holds two files, report-old.txt and report-new.txt. You type less rep and press Tab once. What happens?
-
The shell completes the shared part
report-even when several names match. The line stays the same when there is nothing to add. -
Tab runs nothing; it completes the line. Enter is what runs the command.
-
The shell does not guess which file you need: it completes what the names share.
Both names start with report-, so the shell completes that shared part. The next Tab changes nothing, and one more lists both names. The letter n or o plus a Tab completes the one you need.
Key points
- Tab completes the whole name when one fits, and the shared part when several do.
- When Tab added nothing, the next Tab lists the options. No list means no such name.