30 June 2024

Having a space before your bash command prevents it from being saved to history

Before getting to the topic, I wanted to mention how much more I like the old Reddit. The new one is heavy and really cumbersome to use. I was browsing through Reddit using the old interface, and noticed this post, which mentioned that adding a space before a command prevents it from being written to history. 

Decided to give it a shot. I opened a terminal and typed "hello". Checked  ~/.bash_history, and sure enough, at the end of the file there was "hello".

Then I typed " pwd" (note the space prepended), and the command was not added to the Bash history file. HISTCONTROL even allows avoiding duplicates.

Why aren't these taught in college?