0
0
Linux CLIscripting~20 mins

History command and search in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
History Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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:
history | grep ls
Linux CLI
history | grep ls
A
  1  ls -l
  2  cd /var
  3  ls -a
B
ls -l
ls -a
C
  1  ls -l
  3  ls -a
D 2 cd /var
Attempts:
2 left
💡 Hint
The grep command filters lines containing 'ls' from the history output.
💻 Command Output
intermediate
1:30remaining
Effect of reverse search with Ctrl+R
If you press Ctrl+R in a Linux terminal and type 'git', what will happen?
AIt opens the git manual page.
BIt shows the most recent command in history containing 'git'.
CIt deletes the last command from history.
DIt clears the terminal screen.
Attempts:
2 left
💡 Hint
Ctrl+R is used for reverse search in command history.
📝 Syntax
advanced
1: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?
Ahistory | grep docker
Bgrep docker history
Chistory grep docker
Dhistory -search docker
Attempts:
2 left
💡 Hint
Use pipe to send history output to grep.
🔧 Debug
advanced
2:00remaining
Why does this history search command fail?
A user runs this command:
history | grep 'apt-get update'
But it returns no results, even though they ran 'sudo apt-get update' earlier. Why?
ABecause the command in history includes 'sudo' and the search is for 'apt-get update' only.
BBecause grep cannot search for strings with spaces.
CBecause history does not store commands with sudo.
DBecause the history command needs root privileges to show all commands.
Attempts:
2 left
💡 Hint
Check the exact text stored in history.
🚀 Application
expert
2: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?
Ahistory | sort | grep ssh | uniq | wc -l
Bhistory | grep ssh | uniq | wc -l
Chistory | grep ssh | wc -l
Dhistory | grep ssh | sort | uniq | wc -l
Attempts:
2 left
💡 Hint
You need to filter, sort, remove duplicates, then count lines.