15

Or to phrase it differently, why would you want to prevent commands from being written to the bash history?

(Inspired by a related question.)

1

3 Answers 3

20

The one thing I use that the initial space for is if I want to be able to restart an older commandline that starts with the same command (!ls e.g.) and I need to be able to re-execute the older one, but not the newer.

The other time I use it is in the (seldom) cases I give a password on the commandline, I rather not have those stored in the .bash_history file once I exit bash.

5

I'd rather not know how many times I've played crawl!

Occasionally I like to do a history | awk '{print $2}' | sort -n | uniq -c | sort -n | tail to see my most-issued commands. I want to see a ranking in there of commands I find interesting (things like ls, svn, p4, for, and cd) and I feel better when I don't see games in that list. So when I run something that I don't want to see in that list, I prefix it with a space.

3
  • 1
    This doesn't really answer the Q.
    – slm
    Feb 20, 2014 at 6:42
  • 3
    I don't know: it is a valid use of the variable (and it is expressed with a degree of humour and geekiness). Upvoted.
    – jasonwryan
    Feb 20, 2014 at 7:20
  • you can add the games you play to HISTIGNORE to avoid getting it in history file
    – theist
    Nov 24, 2015 at 8:10
3

In addition to Anthon: It is not just possible to avoid similar command lines in history but from time to time there is a need to do that: I often analyze OpenPGP certificates in the shell. That means that 15 lines (sometimes more) are thrown in the console. You do that a few times and your history is full. Even worse: History does not work well if the command covers the whole screen (bash). The start of the command is not shown correctly and thus can hardly be edited.

Thus I keep a rather short one of these command lines in the history and block the other ones.

1
  • You should make your bash history size (number of items or lines) unlimited export HISTFILESIZE=-1
    – altmas5
    Mar 10, 2016 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.