Space Before Command Not Working on Linux Mint

Bash has a useful feature where it won’t store command history if the command begins with a space.  This was Ubuntu’s default functionality, and it’s useful for commands like:

mysqldump -u root -prootpassword db_name > db_name.export.sql

Unfortunately, this wasn’t enabled by default on Mint, and I was able to do so by adding  the following line to my ~/.bashrc:

HISTCONTROL=ignorespaces:ignoredups

The ignorespace flag won’t store commands whose first character is a space, and ignoredups intuitively causes bash to not store duplicates (when entered sequentially). If using the two together, you can also specify ignoreboth, rather than spelling it out.

ignoredups vs. erasedups

There’s another setting for duplicates – erasedups. While ignoredups prevents repeated entries, erasedups will erase any older instances of the command. I’ll use this series of commands to illustrate the difference.
emacs test.py
emacs test.py
python test.py
emacs test.py

With ignoredups only, your history would look like this:
emacs test.py
python test.py
emacs test.py

With erasedups, your history would look like so:
python test.py
emacs test.py

Of course, you’ll need to restart your bash session (log out/log in, type ‘bash’, etc) for these changes to take effect.

Space Before Command Not Working on Linux Mint

Leave a Reply