recentpopularlog in

kme : histfile   6

How (and Why) to Log Your Entire Bash History
Interesting technique, but as mentioned in the comments, you can use Bash's built-in features to do basically the same thing.

Curiously, this was the same basic approach as in the "eternal history" article at https://debian-administration.org/article/543/Bash_eternal_history.
interesting  bash  history  histfile  promptcommand  dotfile 
july 2019 by kme
Preserve bash history in multiple terminal windows - Unix & Linux Stack Exchange
True dat:
@Oli wrote, "I can't think of an intelligent way to do it where existing terminals only see their own history but new ones see a chronologically accurate list of commands." How about (untried): export PROMPT_COMMAND="history -a; $PROMPT_COMMAND". Existing shells will add each command to the history file for new shells to see, but only show their own histories.


Many solutions proposed, all with caveats, but this is what I decided on:

<code class="language-bash">
HISTCONTROL=ignoredups:erasedups # no duplicate entries
HISTSIZE=100000 # big big history
HISTFILESIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite

# append current history list to the history file after each command finishes
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"</code>

This appends lines to the history file after each command, which makes them available in other sessions, but up arrow will still reverse through the history only for the current session, which is probably less confusing.

You can bring in commands from other sessions (which have been written to the history file) with 'history -n'. Depending on the setting of 'HISTCONTROL', these might end up getting written out to the history file again, though. ¯\_(ツ)_/¯
bash  history  histfile  historyexpansion  frustration  configfile  forthecomments  solution 
july 2019 by kme
Bash eternal history
Many times I've found myself using Ctrl-R in Bash to get a old command four times the terminal width, just to find out that too many days have passed and it's no longer in the .bash_history file. Here are two lines that will keep track of every command line you type at the bash prompt and use no external processes at all, just plain bash.

My first approach to this problem was increasing the maximum number of lines in the history to a very large quantity. But no matter how large it was, there was always a moment when I needed a long command I typed many months ago and it had already left the history. The current solution came to my mind when I learned about the PROMPT_COMMAND variable, a command that bash executes before showing each prompt. Here are the two lines:
<code class="language-bash">export HISTTIMEFORMAT="%s "
PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER \
"$(history 1)" >> ~/.bash_eternal_history'</code>
bash  history  histfile  configfile  maybesolution 
july 2019 by kme
7 Tips - Tuning Command Line History in Bash - ShellHacks
There's nothing here that isn't in the manual, but it's a concise reference that's all in one place. Every 'shopt' and 'HISTCONTROL' option listed here seems to be supported in Bash 4.1 and above (this means CentOS 6).

The 'PROMPT_COMMAND' example, though, would clobber an existing PROMPT_COMMAND, so do it like this instead:
<code class="language-bash">PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }history -a"</code>
bash  history  histfile  configfile  dotfile  essential  movein  reference 
july 2019 by kme
Improving the security of your SSH private key files — Martin Kleppmann’s blog

olalonde • 3 days ago −
You can also prefix the command by a space in bash and it won't be saved to history.
6 •Reply•Share ›

phil olalonde • 3 days ago −
I believe this only works if you have
$ export HISTIGNORE=' *'

or add the above line to bash_profile

Ralph Ubertang Ellipsis • 4 days ago −
or just read it in as a var then unset it.
•Reply•Share ›
bestpractices  crypto  keys  security  ssh  bash  tipsandtricks  histfile  cya  essential  movein 
may 2013 by kme

Copy this bookmark:





to read