Here are some handy commands for using the bash history that others may or may not find helpful:
Code:
shopt -s cmdhist # save multi-line commands in same hist entryshopt -s histappend # append to history file rather than overwriteshopt -s histreedit # re-edit failed history substitution# command history stuffdeclare -x HISTFILESIZE=131072declare -x HISTSIZE=65536declare -x HISTFILE=~/.bash_historydeclare -x HISTCONTROL=ignoreboth # Don't save lines that start with a space (good for don't save passwords)# If enabled, this causes each command in ~/.bash_history to have a date/time with it, and available for correctly showing in history commandsdeclare -x HISTTIMEFORMAT="%F %T " #prefix history entries with date/time# History printing and searching# hi: print historyalias hi='history $*'# hl print history through lessalias hl='(declare HISTTIMEFORMAT="" ; history $* | less +G)'# hlx print history through lessalias hlx='(l=${1:-15} ; declare HISTTIMEFORMAT="" ; history $* | tail -n $l)'# hlt: print history with date/times through lessalias hlt='history | less +G'# hlx: print last n items ($1=n [15])alias hltx='hltx_() { local l=${1:-15} ; history | tail -n $l ; }; hltx_ $*'# hg: print matching history linesalias hg='hg_() { (declare HISTTIMEFORMAT="" ; history | grep $1 | grep -v hg ; ) } ; hg_ $*'alias hgl='hgl_() { (declare HISTTIMEFORMAT="" ; history | grep $1 | grep -v hg | less +G ; ) } ; hgl_ $*'# hgx: print the n last matching lines: ($1=string $2=n [15])alias hgx='hgx_() { (local l=${2:-15} ; declare HISTTIMEFORMAT="" ; history | grep $1 | grep -v hg | tail -n $l ) } ; hgx_ $*'# hgt: print matching history lines with date/timesalias hgt='hgt_() { history | grep $1 | grep -v hg ; } ; hgt_ $*'alias hgtl='hgtl_() { history | grep $1 | grep -v hg | less +G ; } ; hgtl_ $*'# hgtt: print last n items ($1=string $2=n [15])alias hgtx='hgtx_() { local l=${2:-15} ; history | grep $1 | grep -v hg | tail -n $l ; } ; hgtx_ $*'
Statistics: Posted by bls — Wed Nov 06, 2024 4:07 am