Bird
Raised Fist0
Linux CLIscripting~3 mins

Tab completion in Linux CLI - Commands & Configuration

Choose your learning style10 modes available
Introduction
Typing commands and file names in the terminal can be slow and error-prone. Tab completion helps by automatically finishing words when you press the Tab key, saving time and reducing mistakes.
When you want to quickly complete a file or folder name without typing it all.
When you are unsure of the exact spelling of a command or file.
When you want to see possible options or commands starting with the letters you typed.
When you want to speed up repetitive typing in the terminal.
When you want to avoid errors caused by typos in commands or paths.
Commands
Pressing Tab after typing part of a directory or file name tries to complete it automatically.
Terminal
ls /usr/bi<Tab>
Expected OutputExpected
No output (command runs silently)
This command lists the contents of the /usr/bin directory, showing files and commands available there.
Terminal
ls /usr/bin/
Expected OutputExpected
2to3-3.8 a2p addr2line ar as awk basename bash bunzip2 bzcat bzip2 cat cc chmod chown cp csplit curl cut date dd df diff dirname echo env expand expr false fgrep find fold gawk gcc gdb getconf grep gunzip gzip head hostname id install join kill ld ln ls m4 make man mkdir mktemp more mv nc netstat nm nohup od paste patch ping pr printf ps pwd readlink rm rmdir sed seq sh sha1sum sha224sum sha256sum sha384sum sha512sum sleep sort split stat stty su sum sync tail tar tee test time touch tr true uname uncompress unexpand uniq unlink uptime users wc wget which who xargs yes
Pressing Tab after typing part of a directory name changes it to the full directory name if unique.
Terminal
cd Doc<Tab>
Expected OutputExpected
No output (command runs silently)
Prints the current directory path to confirm you changed to the correct folder.
Terminal
pwd
Expected OutputExpected
/home/username/Documents
Key Concept

If you remember nothing else from this pattern, remember: pressing Tab in the terminal helps you finish typing commands and file names quickly and correctly.

Common Mistakes
Pressing Tab when multiple completions are possible without typing more letters.
The shell cannot guess which option you want and may beep or do nothing.
Type more letters to narrow down the options before pressing Tab again.
Expecting tab completion to work in all terminal programs or remote sessions without proper shell support.
Tab completion depends on shell features and configuration; it may not work everywhere.
Use shells like bash or zsh with completion enabled and check your environment.
Summary
Pressing Tab completes commands and file names automatically in the terminal.
Use Tab to save time and avoid typing errors when working with files and commands.
If multiple options exist, type more letters before pressing Tab again to narrow choices.

Practice

(1/5)
1. What does pressing the Tab key once do in a Linux terminal?
easy
A. Automatically completes the command or filename if there is only one match
B. Deletes the current command line
C. Opens a new terminal window
D. Runs the current command immediately

Solution

  1. Step 1: Understand the function of Tab key in terminal

    Pressing Tab once tries to complete the command or filename you are typing if there is only one possible match.
  2. Step 2: Differentiate from other keys

    Other options like deleting or running commands are not triggered by Tab key.
  3. Final Answer:

    Automatically completes the command or filename if there is only one match -> Option A
  4. Quick Check:

    Tab once = auto-complete [OK]
Hint: Tab once completes if only one match exists [OK]
Common Mistakes:
  • Thinking Tab runs the command
  • Confusing Tab with deleting text
  • Assuming Tab opens new windows
2. Which of the following is the correct way to trigger tab completion for filenames in a Linux terminal?
easy
A. Press Ctrl+C
B. Press Enter key twice
C. Press Tab key once or twice
D. Press Esc key

Solution

  1. Step 1: Identify the key used for tab completion

    The Tab key is used to complete filenames or commands in the terminal.
  2. Step 2: Understand usage of pressing Tab once or twice

    Pressing Tab once tries to complete if one match exists; pressing twice shows all possible matches.
  3. Final Answer:

    Press Tab key once or twice -> Option C
  4. Quick Check:

    Tab key triggers completion [OK]
Hint: Use Tab key once or twice for completion or options [OK]
Common Mistakes:
  • Pressing Enter instead of Tab
  • Using Ctrl+C which cancels commands
  • Pressing Esc which does nothing for completion
3. You have files named report1.txt, report2.txt, and report_final.txt in your directory. You type cat rep and press Tab twice. What will happen?
medium
A. The terminal will give an error
B. The terminal will show all files starting with 'rep'
C. The terminal will complete to 'report1.txt' automatically
D. Nothing will happen

Solution

  1. Step 1: Understand double Tab behavior

    Pressing Tab twice after partial typing shows all possible matches starting with that text.
  2. Step 2: Apply to given files

    Since multiple files start with 'rep', the terminal lists all matching files.
  3. Final Answer:

    The terminal will show all files starting with 'rep' -> Option B
  4. Quick Check:

    Double Tab = list matches [OK]
Hint: Double Tab lists all matching files [OK]
Common Mistakes:
  • Expecting auto-completion with multiple matches
  • Thinking it causes an error
  • Assuming no response on double Tab
4. You try to use tab completion but nothing happens when you press Tab. What could be the reason?
medium
A. There are no matching commands or files to complete
B. You pressed Tab too quickly
C. The terminal is frozen
D. Tab completion is disabled by default in Linux

Solution

  1. Step 1: Check if matches exist

    Tab completion only works if there is at least one matching command or filename.
  2. Step 2: Understand other options

    Pressing Tab quickly or terminal freezing are unrelated; Tab completion is enabled by default in most shells.
  3. Final Answer:

    There are no matching commands or files to complete -> Option A
  4. Quick Check:

    No matches = no completion [OK]
Hint: No matches means Tab does nothing [OK]
Common Mistakes:
  • Thinking Tab completion is off by default
  • Blaming terminal freeze without checking
  • Assuming speed of pressing Tab matters
5. You want to list all files starting with doc in a directory, but you only remember part of the filename. You type ls doc and press Tab twice but see too many options. How can you narrow down the tab completion results?
hard
A. Use the Up arrow key to see previous commands
B. Press Ctrl+Z to pause the terminal
C. Restart the terminal and try again
D. Type more characters after 'doc' before pressing Tab again

Solution

  1. Step 1: Understand how tab completion filters matches

    Typing more characters narrows down the possible matches for tab completion.
  2. Step 2: Apply this to the problem

    Adding more letters after 'doc' before pressing Tab reduces the list of files shown.
  3. Final Answer:

    Type more characters after 'doc' before pressing Tab again -> Option D
  4. Quick Check:

    More chars = fewer matches [OK]
Hint: Add more letters before Tab to narrow matches [OK]
Common Mistakes:
  • Pressing Ctrl+Z which suspends processes
  • Restarting terminal unnecessarily
  • Using Up arrow which recalls commands, not files
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard