Accessing your historical bash commands instantly !




As a tester, you might be testing several systems and each have different commands. A common interface might be the bash shell.

How do you get all the previous commands you typed in bash before? Once you close the bash command?

I struggled with this for a few days, and even wrote down commands in notepad, so that i can use them later. Later, I wondered how easy my work would become if i could type the first word of my command and i could search through my bash history.

The problem

Lets say, i used the following command a few days ago to encrypt a file using gpg.


$ gpg --encrypt -r <> REGISTER.ABCD.01102018.917.csv 

Today, I want to encrypt a new file. I know I used gpg before, but I don't remember the exact syntax. 

So I want to type gpg in my command prompt and then use my arrow keys
"up" or "down" to search through my bash history.

Solution

Add the following two lines to your ~/.inputrc

"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

Now you are able to search through your history.

Another neat thing you can do is to increase the size of your history permanently, so that you have a huge list of commands to choose from.


Edit your ~/.bashrc file and add the following two lines.

export HISTSIZE=1000000
export HISTFILESIZE=1000000000

Comments

Popular posts from this blog

The pesky scrollbars on Remote desktop - Finally fixed!!

Exploring RedCritter - website for Agile project mangement

API Testing with Rest Assured - Validating the json schema