Published at
Updated at
Reading time
This post is part of my Today I learned series in which I share all my web development learnings.

Assim Hussain shared on Twitter that he executed a dangerous command by mistake. The command was still accessible in his shell history, and he pressed the UP arrow one time too much.

I have been in that situation, and you may have been, also. ๐Ÿ™ˆ

I like about Twitter that sometimes people reply with useful tips to avoid future mistakes. So did Philippe Martin. He shared that commands executed with a preceding space will not go it into the session history. That sounds great!

# command goes into the history
$ delete everything

# command does not go into the history
$  delete everything

I tried it right away, but it didn't work. I'm a Zsh user, and it turns out that you have to enable it via a config in your .zshrc.

setopt histignorespace

In bash, it should work right away (not tested).

Edited: In bash, the environment variable HISTCONTROL has to be set.

There is one thing to mention though. After the execution of a command, every command will be accessible by pressing the UP arrow (this is a feature). Only when you execute another command preceding space command will be inaccessible.

This little trick prevents your future self from executing a dangerous command when pressing the UP arrow one time too much. ๐ŸŽ‰

Preceeding space terminal demo

Was this TIL post helpful?
Yes? Cool! You might want to check out Web Weekly for more quick learnings. The last edition went out 2 days ago.

Related Topics

Related Articles

About the author

Stefan standing in the park in front of a green background

Frontend nerd with over ten years of experience, "Today I Learned" blogger, conference speaker, Tiny helpers maintainer, and DevRel at Checkly.