Live data from Hacker News

How and Why to Log Your Bash History

spin.atomicobject.com

81–90 of 139 posts

Re: How and Why to Log Your Bash History

#81
post #73

Earlier quoted context omitted.

If you find yourself doing a series of `cd` and `ls` commands frequently, I feel like you might be using `cd` and tab completion ineffectively. Instead of doing: ls cd foo/ ls cd bar/ ls cd baz/ You can do: ls cd foo/ bar/ baz/ This isn't what it will look like, it's just the key sequence (if this doesn't make sense let me know and I'll try to explain better). will list all the possible completions, which is equivale…

Tab autocomplete will show everything, and showing a screen full of name is not particularly useful. Most of the time I use ls it's something like "ls (asterisk)foo(asterisk)". How do I escape asterisk on HN? :O

You can so the same with tab . Eg foo/(asterisk)bar

Re: How and Why to Log Your Bash History

#82
post #11
post #3

Earlier quoted context omitted.

For better history across different terminal (on the same computer) you may want to try zsh

For better pretty much everything, one may wish to try zsh. It's pretty much a strict superset of bash, but better. There is one aspect in which it's significantly worse, though: it's fiendishly difficult to configure and understand. I just use configs provided by others, which is not ideal but works.

Or fish shell! It's autocomplete is the bomb.

Re: How and Why to Log Your Bash History

#83
post #55

Earlier quoted context omitted.

Servers should have zero history saved on the disk. It gives any intruder an easy place to look for passwords, private keys, etc that may have been accidentally recorded and gives clues about related systems. If you have administrative stuff you need to do more than once, write a little script or alias for it. Depending on history for this is just lazy.

OTOH what about audit trail? Are there any standard solutions for saving commands input at servers without giving person inputting those commands access to the logs? Also, silly idea for a DOS attack vector: script-spam enough commands to have the audit history consume all available space on server.

We use rootsh[1] logging to syslog, which gets forwarded to a logging server, which in turn is periodically copied to a wholly separate AWS account, so that in case of breach of the main account the audit logs are intact.

[1] http://linux.die.net/man/1/rootsh

Re: How and Why to Log Your Bash History

#84

A 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.

there's nothing wrong with uploading your dotfiles -- lots of people do that -- just as long as you do it sanely and don't upload things like .ssh/id_* and .{bash|zsh}_history

Re: How and Why to Log Your Bash History

#85
post #32

I'm a big fan of saving history - trying to remember all the shell based commands we use is a nightmare! If you're using zsh, a tip I picked up from [0] was to alias all your common commands like 'cd', 'ls' 'fg'... to: ' cd' ' ls' ' fg' ... Then add the following line to your zshrc to ignore lines prepended with a space: setopt HIST_IGNORE_SPACE This keeps your history cleaner from any ls, cd, fg inputs you use. [0]…

Dropping the ls, ok. But cd conveys relevant context. It would be really clever if a series of cd/ls rolled into a final absolute path cd so history shows context for the subsequent batch of commands.

I just do:

function cd () { builtin cd "$@" && ls; }

Re: How and Why to Log Your Bash History

#86
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.

Re: How and Why to Log Your Bash History

#87
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.

Yep, also back in the day it was common protocol to have .history files chmod'd to 600 by default.

Having an unlimited history is great. Sometimes there'd be a tool or resource I'd vaguely remember skimming (e.g., "oh yeah, I was working on ___, so it must have been on (day +/- 24 hours)". I'd find a command that more or less is chronologically synced with the command, then go into Chrome's SQLite history db in my User Profile to find it.

Re: How and Why to Log Your Bash History

#88
At 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

#89
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.

The porn example was a joke; the ssh example wasn't.

Re: How and Why to Log Your Bash History

#90
post #76
post #73

Earlier quoted context omitted.

Tab autocomplete will show everything, and showing a screen full of name is not particularly useful. Most of the time I use ls it's something like "ls (asterisk)foo(asterisk)". How do I escape asterisk on HN? :O

In zsh, you can complete a glob.

bash too
Post reply on HN