The history -r ensures that all terminals are always synced with the latest 
history commands from all other terminals,
because the read from file only occurs when a terminal is started. 

You are right, it can be slow if the history file grows too large; in
which case just settle for "history -a" - everything is kept but recent
commands typed in other terminals are not available.

I like to keep the full history for analysis purposes, see 
http://www.oreillynet.com/onlamp/blog/2007/01/whats_in_your_bash_history.html
but in order to keep the file size small for quicker loading, I am using the 
following script as a workaround to archive and remove duplicate entries:

#!/bin/bash

let count=1

#Backup history so far
if [[ ! -e ~/bash_history.bck.1 ]]; then
  cat ~/.bash_history > bash_history.bck.1
else #Only backup new bits.
  while [[ -e ~/bash_history.bck.$count ]]; do
    let "count += 1"
  done
  let "last=count-1"
  new_line=`nl -n rz ~/.bash_history | grep "==== bck" | tail -n 1 | cut -c1-6`
  #make sure it is interpreted in decimal
  new_line=$(( 10#$new_line ))
  echo $new_line
  split -a1 -l $new_line ~/.bash_history ~/bash_history.bck.$count
  rm bash_history.bck.${count}a
  mv bash_history.bck.${count}b bash_history.bck.${count}
fi

#Remove duplicates from history but retain ordering
nl -n rz ~/.bash_history | sort -k2 -u | sort | cut -f2- > ~/.bash_history
#history | sort -k2 -u | sort -n | cut -f2-
# Add a marker line to separate new history from compressed history.
echo ===================================== bck.$count === `date` >> 
~/.bash_history

exit

-- 
bash HISTCONTROL=erasedups should erase duplicates from history file before 
saving
https://bugs.launchpad.net/bugs/189881
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to