Thank you!! Why on earth isn't that the default. It always seemed weird that with multiple bash windows open, the commands from most of them weren't added to the history.
Heh. This is funny timing, as .bash_history made me feel like an idiot just yesterday morning.
I was sitting here between queries and I thought 'y'know, all I ever do with history is grep for things. I wonder what else I can do?' When I want to learn about something quick, I usually start with the built-in help; so I did
history --help
The built-in help for history, unfortunately, is woefully inadequate; this was the output:
history: usage: history [-c] [-d offset] [n] or history -awrn [filename] or history -ps arg [arg...]
I said to myself: "Hmm. Wonder what those do?" -- and in a moment of bash stupidity, I thought: "well, let's try it!"
history -c
There's no output from that command, but it didn't take long to figure out what it does. It deletes your entire bash history, clearing the history in RAM and emptying .bash_history.
Since I use history all the time, I panicked. Holy crap! What have I done? I spent a few minutes internalizing the obvious lesson that everybody knows - never run commands without knowing them first. Thankfully, though, I had another bash open at the time. And after I'd beaten myself up over it, I thought for a moment, jumped over to the other shell, and did:
cd && history | cut -c 8- >> .bash_history
... because (after all) the evil, evil history -c command doesn't kill the history from RAM in other shells.
I understand your comment. Intuitively I agree with you but in the context of one of the original devs writing bash it would make no sense to tie the history command to the interactive REPL. Treating everything the same would lead to less bugs in "their" system while leaving a caveat for all the userland script writers.
Why even store your bash history? It's like you store everything you ever said... Would you lose your precious time to go through the old stuff? I wouldn't.
I have a little bit of bash to save my history files and a custom search, hss, to search across them. This makes the exposure an order of degrees, if it's in bash history already then it's going to hang around longer. If I weren't doing this if still have the same problem with bash's built-in/default history.
I started this in response to a HN post some years ago.
Just fix bash so it saves every line of your history ever, no exceptions and no deletions. (Except for the 'leading space' trick when security considerations are in play.)
It's insane that this isn't the default behavior and can't even be configured in 2021!
I maintain almost all my bash history and I often use it to reconstruct a sequence of events in the past when I feel like maybe a mistake had been made.
reply