No shell history at all
I was a bit miffed when shells started saving history to disk (and even moreso when I discovered BSD process accounting). It turns out several people here on Gemini are getting into shell history techniques and sharing tips:
A brief history
A briefer history
Over the years I've changed how I used shell history. But recently I've switched to Simon Tatham's policy of no history. It's not just about the risk of getting hacked (in which case one must also be worried about application-specific history like .lessrc) but about not *relying* on transient data being there unintentionally:
Policy of Transience (sgt20)
The history features of UNIX shells such as bash are not particularly "discoverable". It was years before I learnt about ^R to search back through the recent commands. There seem to be at least the following:
- using the arrow keys (or Emacs/vi bindings) to move back through the history; shells were hell before this was enabled by default
- using ^R to radix search through previous commands
- using "!"-based replacements: "!!" "!-1" "!55" and "!$" to recall whole or partial previous commands
- using "^phrase^replacement" to edit the previous line, which I guess is the most obscure
The downside of the no-history tradeoff is that shell history when it gets long enough is a statistical source of information about potential automation: if you're typing the same command lots of times, that may be a clue that you should set up an alias or save the command as a script with proper documentation and version control. My technique for capturing these was this tiny shell function, which is still in my ~/.alias:
tabulate-history ()
{
history | awk '{$1 = ""; print}' | sort | uniq -c | sort -nr
}
This would tell me my most often used shell commands, which was a fruitful source of time-saving automations. I commend it to the house.
Gemlog index
Site index