1. Increase the number of recalled commands
If you want your system to remember more commands, we will need to edit the bashrc-file. Open your terminal emulator (Konsole/XTerm, etc.)
Code: Select all
nano ~/.bashrc
Code: Select all
export HISTSIZE=1000
export HISTFILESIZE=2000
Let's increase these numbers to something larger:
Code: Select all
export HISTSIZE=10000
export HISTFILESIZE=20000
Save and exit with Ctrl+x.
If you run into issues, please reduce the number.
2. View your history
You can get a list of your Bash history if you type history in the terminal
Code: Select all
history
3. Editing, clearing and reloading the history file
The command history -a writes new command(s) to the history file
Code: Select all
history -a
For example, to delete command number 25 in the session history list:
Code: Select all
history -d 25
Code: Select all
history -c
Code: Select all
history -r
4. Searching for a command in history
Method 1:
We can use grep to find a particular command, for instance usage of the rm command:
Code: Select all
grep rm ~/.bash_history
Method 2:
In the command line interface, we can search for a command in history, we can use reverse search Ctrl+R. This is paricularly useful if you can't remember the command precisely.
Once you have the terminal emulator open, press the Ctrl and R key.
Then start typing the start of the command, and earlier matches should show.
Press Enter to execute the command or press the right arrow key to exit search without running a command.
That's it. I hope it was useful.
