Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Just gotta set your bashrc!

   # Ensure history is written after every command, allowing it to persist across sessions
   shopt -s histappend  # Append to history instead of overwriting
   PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

   # Set the history size (adjust as needed)
   HISTSIZE=50000   # Number of commands kept in memory
   HISTFILESIZE=1000000  # Number of commands kept in the history file

   # Add timestamps to history (format: YYYY-MM-DD HH:MM:SS)
   HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "

   # Ignore duplicate and space-prefixed commands
   HISTCONTROL=ignoredups:ignorespace

   # Save multi-line commands as a single entry
   shopt -s cmdhist

   # Allow history expansion with Ctrl + R
   bind '"\e[A":history-search-backward'
   bind '"\e[B":history-search-forward'
Also, if you are on shells you worry about, use gnu screen (or tmux if you prefer) imho. It will give you a second layer of history to be able to dig through.


view as:

Legal | privacy