Preventing A Command From Being Logged In Your Bash History

Content:

Your shell history can be incredibly useful, allowing previously executed commands to be cycled through and executed without having to type the command out again.

The history is limited though, and running the same commands a few times can quickly pollute your history with repeated commands.

Fortunately, there’s a very easy way to prevent a command from being logged in your bash history. Simply leave a space at the end of the command, and it wont be logged.

For example, the following command does not have a following space – therefore, it will be recorded in the bash history.

nano /etc/portage/make.conf

A simple tweak to add the space as below is enough to prevent this.

nano /etc/portage/make.conf 

If you copy the text, you’ll see the space appended to the end. This is a very simple trick, which is very useful if you run a lot of terminal commands.