Rewriting History (letter LXF187p93)

Comments, suggestions and questions about Linux Format magazine and the coverdiscs

Moderators: ChrisThornett, LXF moderators

Rewriting History (letter LXF187p93)

Postby johnlane » Tue Jul 15, 2014 9:01 am

A nice letter about the bash history in LXF187. I thought I'd jot down a couple of extra points for anyone interested. Here is my config (in /etc/bash.bashrc):

Code: Select all
export HISTSIZE=999
export HISTFILESIZE=999
export HISTCONTROL=ignoredups:erasedups
export PROMPT_COMMAND="history -n; history -w; history -c; history -r"
export HISTIGNORE=ls:h:history
shopt -s histappend
alias h=history


There are a couple of differences.


    I set HISTSIZE and HISTFILESIZE - the former sets the size of the in-memory buffer and the latter sets the size of the on-disk file.
    I set PROMPT_COMMAND to save and re-load the history. The reasoning for this command sequence is explained here
    I set HISTIGNORE to common commands from being stored.
    I also set 'h' as an alias for 'history' because I like to save six keystrokes :lol:


Something to be aware is that the terminal's history is stored in memory and it is only written to and read from the file when PROMPT_COMMAND is executed. This only happens whenever the prompt is displayed. This means that you need to hit ENTER to update the history.

If you use multiple terminals (which is probably why you'd do this anyway) then you can still experience issues where their histories aren't properly in sync. I don't know why; I just live with it.

If anyone else can suggest anything better it would be good to hear.
johnlane
 
Posts: 16
Joined: Tue Nov 06, 2012 4:55 pm

Return to Magazine and coverdiscs

Who is online

Users browsing this forum: No registered users and 3 guests