Live data from Hacker News

How and Why to Log Your Bash History

spin.atomicobject.com

131–139 of 139 posts

Re: How and Why to Log Your Bash History

#131
post #130

Earlier quoted context omitted.

the difference is that the author's version backs up every command to a file as it happens. If you have multiple terminals open, you do not get the same output running "history".

something other than: shopt -s histappend Isn't that exactly what that shell option does?

That does make multiple terminals play nice with eachother, but it's still different, as OP's still flushes to HISTFILE after every command. But, then we can do that with

    PROMPT_COMMAND='history -a'

Re: How and Why to Log Your Bash History

#132

I like this idea but I know that I have accidentally entered my password or my password with a typo in it on the terminal on at least one occasion. The only way round this that I can see is to grep out the password - but then my password (or a substring of it) is now in plaintext in my .zshrc/.bashrc I can't think of a solution to this. Does anyone have anything?

Start your passwords with /! - the slash stops you entering it into IRC, and the bang stops it going into history.

Re: How and Why to Log Your Bash History

#133
post #112

Earlier quoted context omitted.

Yes, the stars are missing, but not where you think. The --files option has a star on the inside of each quote. This makes the search only show history for the host you are on (I sync my Dotfiles between machines). sift searches a path/folder so the star you have is not needed. But yeah, HOSTNAME_SHORT is something I derive from HOSTNAME.

Thanks for clarifying! Now I'm curious to hear more about how you sync your dotfiles ;-)

Dropbox with a symlink also works fine though I have had it generate conflicts within .ssh folder which I also sync.

Re: How and Why to Log Your Bash History

#135
post #2

Well given that we copy and paste a lot, by mistake there can be credentials and sensitive data in the bash history... Moreover, bash history doesn't work nicely across different terminal tabs or computers. Does anybody know a tool providing better command line history?

https://github.com/dvorka/hstr

Don't know about better, but above certainly makes it much nicer...

Re: How and Why to Log Your Bash History

#137
post #74

I 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/$…

A better solution for that problem is to not screw around with personal garbage on work computers.

That wasn't necessary. You could easily have made the very same point without calling someone's personal pastime/hobby, "garbage".

It's one thing to use porn as an example of "things that may be awkward if found in my bash history", it's something else to get judgemental about it. Unnecessary and off-topic.

Re: How and Why to Log Your Bash History

#138
I have bash script in my bash_profile to support separate history files named with tty, month and year (so separate files for each tty). It looks for recent history files for the given tty and reloads old history on first startup.

Have cron job to signal bash session to flush history with command timestamps/dates to disk daily.

Handy for recalling commands/command switches you ran months ago.

Post reply on HN