π Key Concept: TAB Autocompletion
-
TAB is the most important shortcut for working efficiently in the terminal.
-
Helps avoid mistakes and speeds up typing commands, filenames, or directories.
-
Works with Bash and most other shells.
π§ How It Works
-
Start typing a command, file, or directory name.
-
Press TAB:
-
β If a unique match is found β it autocompletes.
-
β If multiple matches exist β press TAB twice to view suggestions.
-
β οΈ If nothing happens, it means either:
-
There's no match.
-
Thereβs a typo or mistake (e.g., extra whitespace).
-
-
π Examples
-
Typing
ifc+TABβ Autocompletes toifconfig. -
Typing
if+TAB TABβ Shows all commands starting withif.
cat /e + TAB β becomes: cat /etc/
cat /etc/pa + TAB TAB β shows multiple matches
cat /etc/passwd + TAB β autocompletes when unique
π¨ Common Mistakes
- Whitespace before a word prevents autocompletion:
cat /etc/ pa + TAB β wonβt work (extra space)
Manual typing increases risk:
-
Example: typing
/var /log/file.loginstead of using TAB. -
Could make
rm /var /log/file.loginterpret as two arguments (/varand/log/file.log) instead of one path. -
May lead to deleting an entire directory (e.g.,
/var/log).
β Best Practice
π If TAB doesn't autocomplete, stop and check!
Donβt keep typing β it means something is wrong (typo, space, etc.).