Hack 57. Eliminate the continuous repeated entry from history using HISTCONTROL

by Ramesh

In the following example pwd was typed three times, when you do history, you can see all the 3 continuous occurrences of it. To eliminate duplicates, set HISTCONTROL to ignoredups as shown below.

  1. # pwd
  2.  
  3. # pwd
  4.  
  5. # pwd
  6.  
  7. # history | tail -4
  8. 44 pwd
  9. 45 pwd
  10. 46 pwd
  11. 47 history | tail -4

Note: There are three pwd commands in history, after executing pwd 3 times as shown above

  1. # export HISTCONTROL=ignoredups
  2.  
  3. # pwd
  4.  
  5. # pwd
  6.  
  7. # pwd
  8.  
  9. # history | tail -3
  10. 56 export HISTCONTROL=ignoredups
  11. 57 pwd
  12. 58 history | tail -4

Note: There is only one pwd command in the history, even after executing pwd 3 times as shown above