Sat 16 Dec 2006
Controling bash history
Posted by Harry under Linux Web Hosting , Web Hosting , cheap linux web hostingWhile 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 â€
2 Responses to “Controling bash history”
Leave a Reply
You must be logged in to post a comment.



















December 20th, 2006 at 9:09 am
Bash history is primarily for our convenience, a means of saving keystrokes.
Consider following eg :
190 ps -axu | grep htt
191 /www/bin/apachectl start
192 vi /usr/local/lib/php.ini
193 cat /www/logs/error_log
194 ps -auxw | grep http
195 pwd
You can retrieve the old commands using a special symbol “ ! “ followed by initial letters of the command you had typed before. In the example above, ps was ran twice, then pwd. If you typed !p you’d get the output of pwd. Typing !ps is just enough to be unique and will execute the ps -auxw | grep http entry in history. This save your repetitive keystrokes which may be cumbersome and also minimize chances of error.
you can use history -c to empty the bash history file.
January 2nd, 2007 at 6:51 pm
To clear your current working history fire following command on shell
# unset HISTFILE