4 ms·
One tip for your .bashrc I only recently found out and can't do without anymore is one I picked up here (log all shell commands directly to a file): https://www
by janvdberg 3y ago
One tip for your .bashrc I only recently found out and can't do without anymore is one I picked up here (log all shell commands directly to a file): https://www.jefftk.com/p/you-should-be-logging-shell-history https://www.jefftk.com/p/you-should-be-logging-shell-history
- zamnos 3y ago'histgrep' is an interesting one. Bash has a built in backwards search via ^r, which is greatly enhanced by plugging fzf into it.
- cerved 3y agoIdk, the times I grep history I just history | grep Using fzf for backwards search sounds interesting, can you elaborate? My favorite is binding key-up and down to complete using search. That's a game changer
- zamnos 3y agoThe best description I found with a not so short Google was buried in https://www.redhat.com/sysadmin/fzf-linux-fuzzy-finder https://www.redhat.com/sysadmin/fzf-linux-fuzzy-finder but the workflow is I hit ctrl-R (in bash, but there's bindings for other shells), I type out part of the command I know is in my history, and fzf will grep history for commands that match via its fuzzy search algorithm. So if I remember running something that involved a file called something in a log dir, I type /log/, and it interactively lets me search. I remembered I was using awk with the log file, so I can add "awk" to the existing search), and then I use the up arrow to select it and hit enter. at which point it's in my command buffer waiting for me to either hit enter again or edit the command and then hit enter. Might sound complex written out like that, but I promise it's worth the investment to set it up and read the manual.
- bomewish 3y agothis is what mcfly does but it does it all automagically and stores everything in sqlite database. Also easy to sync that db between two computers connected by tailscale/ssh.
- jordemort 3y agoIf you like searching your Bash history with fzf, you're gonna love McFly: https://github.com/cantino/mcfly https://github.com/cantino/mcfly
- Evidlo 3y agoYou can get similar behavior with bash's built-in history by setting a few options: # -------- History -------- #increase bash history HISTFILESIZE=10000000 HISTTIMEFORMAT="%FT%R " HISTSIZE=10000000 # append to .bash_history and reread after each command export PROMPT_COMMAND="history -a;$PROMPT_COMMAND" # append to .bash_history instead of overwriting shopt -s histappend # dont allow repeated lines export HISTCONTROL=ignoredups:erasedups
- geraldhh 3y agowondering if scanning throu >10M history entries, looking for duplicates, will introduce a noticeable ex degradation on lesser systems (rpi etc).
- znpy 3y agoThe file might fit without much problems in the filesystem cache, so i guess it would only be a problem in the first time. I had a friend in university that used a refurbished hp workstation with a shitload of ram as a desktop computer, and he would find | xargs -L1 cat {} > /dev/null everything in his home directory on login to warm up the filesystem cache. The kernel would then drop stuff not actually needed/accessed nicely over time.
- iforgotpassword 3y agoDon't know about erasedups, but the other option just applies to consecutive repeats, so really only had to scan from the end until the first non-dup
- deleted 3y ago[deleted]
- jefftk 3y agoExcept if you ever accidentally open a shell without those settings set (ex: "bash --norc" to get a clean profile) it will trim your decades-long history. Your HISTFILESIZE is also probably not enough: my .full_history goes back to 2012 and is 2.5x your limit.
- deleted 3y ago
- jakebasile 3y agoI like to use atuin for this. Basically indispensable to me now. https://github.com/ellie/atuin https://github.com/ellie/atuin
- iAmAPencilYo 3y agoGreat Atuin, that's amazing. Thank you, this is indeed a game changer for having a permanent history. I use ctrl+r for everything including commands I vaguely remember but know at least some letters
- cerved 3y agoI like saving all my history, but I also find that it easily becomes a mess doing it in one file. So I split it up session, and then I merge it all into one file. # Eternal bash history. # --------------------- HISTCONTROL= HISTFILESIZE= HISTIGNORE= HISTSIZE= HISTTIMEFORMAT="%Y-%m-%dT%T%t" # read global history HISTFILE=~/.bash_eternal_history history -r # IIF there's no session history directory, create one if [ ! -d ~/.bash_history ]; then [ -f ~/.bash_history ] && mv ~/.bash_history ~/.bash_history.0 mkdir ~/.bash_history fi # change history file to one for the session HISTFILE=~/.bash_history/$$ # If it already exists, take a backup if [ -f "$HISTFILE" ]; then mv "$HISTFILE" "$HISTFILE"."$(stat "$HISTFILE" --format='%W')" fi # save the current session id + process id { export SESSION_ID="$(</proc/$$/sessionid)"; } 2> /dev/null printf "#$(date '+%s')"'\n# starting session:'$SESSION_ID' process:'$$' in:'"$PWD"'\n' > "$HISTFILE" && history -r # Use trap to save history, not just on logout but also EXIT trap_exit() { # Append session history to global history ## Append to local history session to file cp -f "$HISTFILE" /tmp/history.$$.0 history -a cp -f "$HISTFILE" /tmp/history.$$.1 ## Append local history file to global history printf "#$(date '+%s')"'\n# ending session:'$SESSION_ID' process:'$$' in:'"$PWD"'\n' | cat "$HISTFILE" - >> ~/.bash_eternal_history } trap trap_exit EXIT
- splitbrain 3y agoThis looks super interesting. I'll give this a go for a while to see how much I like it.
- programmer_dude 3y agoI have never felt the need to explicitly lookup history since I switched to fish shell. It has very good command completion (from history).
- p5a0u9l 3y agoIt’s indispensable in some workflows. Scoring history can help with otherwise difficult debugging, or looking up a variant to a complicated invocation that’s not the one suggested by auto complete.