Hack 58. Erase duplicates across the whole history using HISTCONTROL

by Ramesh

The ignoredups shown above removes duplicates only if they are consecutive commands. To eliminate duplicates across the whole history, set the HISTCONTROL to erasedups as shown below.

  1. # export HISTCONTROL=erasedups
  2.  
  3. # pwd
  4.  
  5. # service httpd stop
  6.  
  7. # history | tail -3
  8. 38 pwd
  9. 39 service httpd stop
  10. 40 history | tail -3
  11.  
  12. # ls -ltr
  13.  
  14. # service httpd stop
  15.  
  16. # history | tail -6
  17. 35 export HISTCONTROL=erasedups
  18. 36 pwd
  19. 37 history | tail -3
  20. 38 ls ltr
  21. 39 service httpd stop
  22. 40 history | tail -6

Note: The previous service httpd stop after pwd got erased