I do the opposite and maybe weird - I disable history, and keep the history file contents hand curated. Whenever I come up/across/use a command I'd like to keep for future or use frequently, it gets appended to the history file.
Do you use the fc command (shell builtin in the case of bash) to access the history? Or just up-arrow to scroll through the options?
How and Why to Log Your Bash History
101–110 of 139 posts
Re: How and Why to Log Your Bash History
#102I used to do the same thing to figure out which commands I should create short aliases for. Sounded like a good idea at the time but then I realized that I'm creating a file with an awful lot of interesting information in it and I not getting a lot in return. So I set my HISTSIZE to 1000 which is more than enough for interactive shell use and I don't have to worry about having stuff like "youtube-dl fuckmesilly.com/$…
Re: How and Why to Log Your Bash History
#103A warning: do NOT do what one engineers I used to work with did, and upload his "dot files" onto GitHub for portability. A lot of secrets can be stored in a few months' worth of bash history.
Re: How and Why to Log Your Bash History
#104I do the opposite and maybe weird - I disable history, and keep the history file contents hand curated. Whenever I come up/across/use a command I'd like to keep for future or use frequently, it gets appended to the history file.
Do you have an alias or something else that facilitates that, or do you just do it manually?
I use `unset HISTFILE` to make sure when I exit the history file doesn't get all the cruft in. Every now and then I might do some housecleaning, including going through the history file then `cp ~/.bash_history{,.2}` to keep a clean copy around.
As far as saving, heres a handy function: `getlast() { fc -ln "$1" "$1" | sed '1s/^[[:space:]]*//' }`
Re: How and Why to Log Your Bash History
#105I do something very similar, but without the prompt settings. I have settings in .bashrc[0] to have the history file based on date. I then use fzf[1] (fzf-tmux is great) and a grep-like tool(sift[2]) to use for ctrl-r that fuzzy-searches history and orders by usage frequency[3]. This way I can easily search for the command I'm thinking of fairly quickly. Particularly useful for those times I want to run a command aga…
Had to tweak mine slightly though:
${HOSTNAME_SHORT} -> ${HOSTNAME}
$HOME/Sync/Dotfiles/history -> $HOME/Sync/Dotfiles/history/*
(maybe the missing star was due to HN formatting?)Re: How and Why to Log Your Bash History
#106I love this idea because you can easily analyse your commands then modify or automate your workflow where it makes sense. I've done this in the past to create a two letter aliases to frequently used bash commands.
[0] export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(hostname) $(tty) $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log.`hostname`; fi'
Re: How and Why to Log Your Bash History
#107Just for those out there using zsh or fish I used to following in my .zshrc to get this working: precmd() { eval 'if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history | tail -n 1)" >>! ~/Dropbox/Logs/Bash/Macbook/bash-history-$(date "+%Y-%m-%d").log; fi' } I Store my logs in dropbox but you can put them wherever
Re: How and Why to Log Your Bash History
#108At work unfortunately the sys admins disable customisation. Especially HIST_SIZE etc :( At regular intervals, especially when I have important commands to save I do a: cp ~/.bash_history ~/bash_history_bak_2016-05-31.txt That way I can do a: cat ~/bash_history* | grep to find it
Re: How and Why to Log Your Bash History
#109I used to do the same thing to figure out which commands I should create short aliases for. Sounded like a good idea at the time but then I realized that I'm creating a file with an awful lot of interesting information in it and I not getting a lot in return. So I set my HISTSIZE to 1000 which is more than enough for interactive shell use and I don't have to worry about having stuff like "youtube-dl fuckmesilly.com/$…
export HISTFILE=
The rest of your session will not be logged.Re: How and Why to Log Your Bash History
#110I do something very similar, but without the prompt settings. I have settings in .bashrc[0] to have the history file based on date. I then use fzf[1] (fzf-tmux is great) and a grep-like tool(sift[2]) to use for ctrl-r that fuzzy-searches history and orders by usage frequency[3]. This way I can easily search for the command I'm thinking of fairly quickly. Particularly useful for those times I want to run a command aga…