A preceding space prevents dangerous commands from going into history (#tilPost)

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 b…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

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. ?


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2018-12-29T23:00:00+00:00) A preceding space prevents dangerous commands from going into history (#tilPost). Retrieved from https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/

MLA
" » A preceding space prevents dangerous commands from going into history (#tilPost)." Stefan Judis | Sciencx - Saturday December 29, 2018, https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday December 29, 2018 » A preceding space prevents dangerous commands from going into history (#tilPost)., viewed ,<https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » A preceding space prevents dangerous commands from going into history (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/
CHICAGO
" » A preceding space prevents dangerous commands from going into history (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/
IEEE
" » A preceding space prevents dangerous commands from going into history (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/. [Accessed: ]
rf:citation
» A preceding space prevents dangerous commands from going into history (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2018/12/29/a-preceding-space-prevents-dangerous-commands-from-going-into-history-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.