Challenge - 5 Problems
History Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of history search with grep
What is the output of the following command sequence in a Linux shell where the history contains these commands:
1. ls -l
2. cd /var
3. ls -a
4. history
Command:
1. ls -l
2. cd /var
3. ls -a
4. history
Command:
history | grep lsLinux CLI
history | grep ls
Attempts:
2 left
💡 Hint
The grep command filters lines containing 'ls' from the history output.
✗ Incorrect
The history command lists all previous commands with their numbers. Grep filters lines containing 'ls'. Only commands 1 and 3 contain 'ls'.
💻 Command Output
intermediate1:30remaining
Effect of reverse search with Ctrl+R
If you press Ctrl+R in a Linux terminal and type 'git', what will happen?
Attempts:
2 left
💡 Hint
Ctrl+R is used for reverse search in command history.
✗ Incorrect
Ctrl+R activates reverse incremental search. Typing 'git' finds the last command with 'git' in history.
📝 Syntax
advanced1:30remaining
Correct syntax for searching history with a pattern
Which command correctly searches the history for commands containing the word 'docker' and shows line numbers?
Attempts:
2 left
💡 Hint
Use pipe to send history output to grep.
✗ Incorrect
The history command outputs the list, which can be piped to grep to filter lines containing 'docker'.
🔧 Debug
advanced2:00remaining
Why does this history search command fail?
A user runs this command:
But it returns no results, even though they ran 'sudo apt-get update' earlier. Why?
history | grep 'apt-get update'But it returns no results, even though they ran 'sudo apt-get update' earlier. Why?
Attempts:
2 left
💡 Hint
Check the exact text stored in history.
✗ Incorrect
The command stored was 'sudo apt-get update', so searching for 'apt-get update' alone does not match.
🚀 Application
expert2:30remaining
Count how many unique commands contain 'ssh' in history
You want to find out how many unique commands in your history contain the string 'ssh'. Which command will give you the correct count?
Attempts:
2 left
💡 Hint
You need to filter, sort, remove duplicates, then count lines.
✗ Incorrect
Piping history to grep filters lines with 'ssh'. Sorting is needed before uniq to remove duplicates correctly. Then wc -l counts lines.