0
0
Linux CLIscripting~15 mins

History command and search in Linux CLI - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the History Command and Search in Linux CLI
📖 Scenario: You are working on a Linux terminal and want to efficiently reuse commands you typed before. The history command helps you see past commands, and searching through history saves time.
🎯 Goal: Learn to list your command history, set a limit on how many commands are saved, search your history for specific commands, and display the search results.
📋 What You'll Learn
Use the history command to list past commands
Create a variable to set the history size limit
Use history with grep to search for commands containing a keyword
Print the search results
💡 Why This Matters
🌍 Real World
Using command history saves time by reusing previous commands instead of typing them again.
💼 Career
System administrators and developers often use history commands to speed up their work and avoid mistakes.
Progress0 / 4 steps
1
List your command history
Type the command history to list your past commands in the terminal.
Linux CLI
Need a hint?

The history command shows the list of commands you typed before.

2
Set the history size limit
Create a variable called HISTSIZE and set it to 50 to limit the number of commands saved in history.
Linux CLI
Need a hint?

Use HISTSIZE=50 to keep only the last 50 commands in history.

3
Search your history for a keyword
Use history | grep ls to search your command history for all commands containing the word ls.
Linux CLI
Need a hint?

The pipe | sends the output of history to grep which filters lines containing ls.

4
Display the search results
Print the output of history | grep ls to see all previous commands that include ls.
Linux CLI
Need a hint?

Running history | grep ls again will show the filtered commands.