The history command shows a list of commands you have typed before in the terminal. It helps you see past commands to reuse or review them.
Click to reveal answer
beginner
How do you search your command history interactively in Linux?
Press Ctrl + R to start a reverse search. Then type part of the command you want to find. The terminal will show matching commands from your history.
Click to reveal answer
intermediate
What does the command !123 do in the Linux shell?
It runs the command numbered 123 from your history list. This lets you quickly repeat a past command by its history number.
Click to reveal answer
beginner
Explain the use of !! in the Linux shell.
!! repeats the last command you typed. It is a quick way to run the previous command again without retyping it.
Click to reveal answer
intermediate
How can you limit the number of commands shown by the history command?
Use history | tail -n N where N is the number of recent commands you want to see. For example, history | tail -n 10 shows the last 10 commands.
Click to reveal answer
Which key combination starts a reverse search in the Linux command history?
ACtrl + R
BCtrl + S
CCtrl + H
DCtrl + L
✗ Incorrect
Ctrl + R starts a reverse search to find commands in your history.
What does the command !ls do?
ARuns the last command starting with 'ls'
BLists files in the current directory
CShows the history of 'ls' commands
DDeletes the last 'ls' command from history
✗ Incorrect
!ls runs the most recent command that starts with 'ls' from your history.
How do you repeat the last command you typed?
ACtrl + C
B!!
Chistory
D!1
✗ Incorrect
!! repeats the last command entered.
What does history 5 show?
AThe first 5 commands typed
BAll commands except the last 5
CThe last 5 commands typed
DThe 5th command in history
✗ Incorrect
history 5 lists the last 5 commands you typed.
Which command lets you run a command from history by its number?
Arepeat number
Bhistory number
Crun number
D!number
✗ Incorrect
Using !number runs the command with that history number.
Describe how to search and reuse a previous command using the Linux history feature.
Think about interactive search and shortcuts to rerun commands.
You got /5 concepts.
Explain the purpose and basic usage of the history command in Linux.
Focus on how history helps with command reuse.
You got /4 concepts.
Practice
(1/5)
1. What does the history command do in a Linux terminal?
easy
A. Deletes all saved commands
B. Lists all previously executed commands
C. Shows current running processes
D. Clears the terminal screen
Solution
Step 1: Understand the purpose of history
The history command shows a list of commands you typed before in the terminal.
Step 2: Compare options with command behavior
Only Lists all previously executed commands correctly describes this behavior; others describe different commands.
Final Answer:
Lists all previously executed commands -> Option B
Quick Check:
history lists past commands [OK]
Hint: Remember: history shows past commands typed [OK]
Common Mistakes:
Confusing history with clearing screen
Thinking history deletes commands
Mixing history with process listing
2. Which of the following is the correct syntax to rerun the last command starting with git?
easy
A. !!git
B. !$git
C. !git
D. !^git
Solution
Step 1: Recall syntax for rerunning commands by prefix
Using !string reruns the last command starting with string.
Step 2: Analyze options
!git reruns last command starting with 'git'. Others are invalid or incorrect syntax.
Final Answer:
!git -> Option C
Quick Check:
Use !string to rerun commands [OK]
Hint: Use ! plus command start to rerun quickly [OK]
Common Mistakes:
Using !!git which is invalid
Confusing !$ with rerun syntax
Trying !^git which is not correct
3. Given the following history output:
100 ls -l 101 git status 102 cd projects 103 git commit -m 'fix'
What command will run if you type !git?
medium
A. git commit -m 'fix'
B. git status
C. ls -l
D. cd projects
Solution
Step 1: Identify last command starting with 'git'
From history, commands 101 and 103 start with 'git'. The last one is 103: git commit -m 'fix'.
Step 2: Understand !git runs last matching command
!git reruns the most recent command starting with 'git', which is command 103.
Final Answer:
git commit -m 'fix' -> Option A
Quick Check:
!string runs last command starting with string [OK]
Hint: !string runs last command starting with string [OK]
Common Mistakes:
Choosing first matching command instead of last
Confusing command numbers with commands
Selecting unrelated commands
4. You tried to rerun a command with !cd but got an error: bash: !cd: event not found. What is the likely cause?
medium
A. The shell does not support history
B. You typed the command incorrectly
C. You need to use !! instead
D. No previous command starts with 'cd' in history
Solution
Step 1: Understand error meaning
event not found means no matching command found in history for the given prefix.
Step 2: Analyze cause
If no previous command starts with 'cd', !cd fails with this error.
Final Answer:
No previous command starts with 'cd' in history -> Option D
Quick Check:
!string fails if no matching command [OK]
Hint: Check history for matching commands before using !string [OK]
Common Mistakes:
Assuming syntax error instead of missing history
Thinking shell lacks history support
Using !! instead of !string incorrectly
5. You want to find and rerun a command that contains the word backup anywhere in it, but you don't remember the exact command start. Which is the best way to do this?
hard
A. Press Ctrl + r and type 'backup' to search interactively
B. Use !backup to rerun the command
C. Run history | grep backup and then rerun manually
D. Use !! backup to rerun last backup command
Solution
Step 1: Understand searching commands with unknown start
!string only matches commands starting with string, so !backup won't find commands containing 'backup' elsewhere.
Step 2: Identify interactive search method
Ctrl + r lets you search history interactively for any substring, including 'backup'.
Final Answer:
Press Ctrl + r and type 'backup' to search interactively -> Option A
Quick Check:
Use Ctrl + r for substring history search [OK]
Hint: Use Ctrl + r to search history by any word quickly [OK]
Common Mistakes:
Assuming !backup matches anywhere in command
Trying !! backup which is invalid syntax
Relying only on grep without rerun shortcut
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.