Skip bash command history

John Rix
2 min readDec 18, 2019

--

Photo by NeONBRAND on Unsplash

Purely by accident, I learned something new and useful about bash today, after using it for 20+ years.

Everybody knows (or should know) that using passwords directly on a command line is a bad practice, among other reasons, because it will leave these in your command history, potentially to be discovered by others in future.

If you really need to use a password on the command line though, and circumstances mitigate the risks associated with doing so, you can force bash not to include your command in your history simply by preceding your command with a space character!

Naturally, this behaviour has uses beyond just avoiding passwords in bash history though also. Think destructive commands that you don’t want to accidentally pick from your command history in too much of a hurry (rm -rf * ⬅ I’m looking at you), or if you are re-using a command repeatedly for some reason but need to do something else for a moment and don’t want to interrupt your muscle memory from the main task thereafter (a bit of a stretch, admittedly, but I’ll find it useful for that at least).

This feature of bash is governed by the HISTCONTROL environment variable, which has a couple of other useful settings worth reading up on also.

And with this knowledge snack in hand, go forth and make flippant article closings!

Or not.

(Forgive the tenuous connection with the chosen image… ‘skip’. Sorry.)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response