While working on the bash shell we sometimes requires to use some commands frequently. Instead of typing and recalling previous commands you configure your bash history setting to run your commandline operations smoothly.

Following settings will help you :

*) Don’t save duplicates :

HISTCONTROL=ignoreboth
Using this command we ignore any lines matching the previous history and are not saved. Other options for HISTCONTROL: ignorespace, lines which begin with a space character are not saved in the history list; erasedups causes all previous lines matching the current line to be removed from the history list before that line is saved.

*) Size of the history:

HISTSIZE=500
Using this we can set the number of commands to remember in the command history. The default value is 500.

*) Others:

HISTFILE:
The name of the file in which command history is saved.
Generally it is at ~/.bash_history.

HISTIGNORE:
A colon-separated list of patterns used to decide which command lines should be saved on the history list.

We set these options either by export them in your environment in your personal bash configuration file (~/.bashrc) or in the global bash configuration file (/etc/bash.bashrc). The name of the configuration files can depend from your Linux distribution and bash version.
To get activated these setting you need to restart your bash session.
To verify your configuration setting type env at the command prompt.

Tip : “ The most efficent way to search your history is to hit Ctrl R and type the start of the command. It will autocomplete as soon as there’s a match to a history entry, then you just hit enter ”