010-160 Command Line Navigation 4 — Questions and Answers
Question 1: Which special shell variable holds the exit status of the last executed command?
- $!
- $0
- $? (Correct answer)
- $$
Correct answer: $?
`$?` contains the exit status of the most recently executed foreground command; 0 means success.
Question 2: What does pressing Tab once do in the bash shell when typing a command?
- Inserts a literal tab character
- Attempts to auto-complete the command or filename (Correct answer)
- Moves to the next command in history
- Clears the current line
Correct answer: Attempts to auto-complete the command or filename
Tab completion in bash automatically completes the command name, filename, or path if there is an unambiguous match.
Question 3: Which command shows the manual page (documentation) for a given command?
- help
- info
- man (Correct answer)
- doc
Correct answer: man
`man <command>` opens the manual page for that command, providing detailed usage information and options.
Question 4: In the output of `ls -l`, what does the first character of the permission string indicate?
- The owner's read permission
- The file type (e.g., - for regular, d for directory) (Correct answer)
- The number of hard links
- The group ownership
Correct answer: The file type (e.g., - for regular, d for directory)
The first character in `ls -l` output indicates the file type: `-` for regular file, `d` for directory, `l` for symbolic link.
Question 5: Which key combination cancels the current command line input in bash?
- Ctrl+Z
- Ctrl+C (Correct answer)
- Ctrl+D
- Ctrl+X
Correct answer: Ctrl+C
Ctrl+C sends SIGINT to the foreground process, canceling the current command or interrupting a running program.
Question 6: What is the purpose of the `which` command?
- Shows which users are logged in
- Locates the executable file for a given command (Correct answer)
- Lists all available shell commands
- Displays which partitions are mounted
Correct answer: Locates the executable file for a given command
`which <command>` searches the directories in $PATH and prints the full path of the executable that would be run.
Question 7: How do you display the last 10 commands from your shell history?
- history | head
- history 10
- history | tail (Correct answer)
- last 10
Correct answer: history | tail
`history | tail` pipes the history list to `tail`, which by default shows the last 10 lines.
Which special shell variable holds the exit status of the last executed command?