Ignore duplicate entries in the bash history

As you know, bash keeps a history of the commands used in your user’s session. But, when you use a command twice (or more), it will be saved with two (or more) entries in the bash history.

The best way to get rid of the duplicated entries is to add this in your ~/.bashrc file.

$ echo 'export HISTCONTROL=ignoreboth:erasedups' >> ~/.bashrc

Explenation, from the bash manual:

HISTCONTROL=ignoreboth:erasedups – ignore the duplicates and the command starting with space and remove the previous line matching with the line of the current command.

HISTCONTROL=ignoreboth – ignore the duplicates and the commands starting with spaces.

HISTCONTROL=ignoredups – ignore only the duplicates.

HISTCONTROL=ignorespace – ignore only the commands starting with space.

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Support LinuxG via Patreon
Support LinuxG.net on Patreon!
Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!