Live data from Hacker News

“I have [bash] history back to ~2003”

twitter.com

71–80 of 148 posts

Re: “I have [bash] history back to ~2003”

#71
post #29

Here's something interesting - We collected bash history of around 15000 users and listed frequented used commands for fun :) http://www.webminal.org/fulc/

Doing this on my own bash_history is what prompted me to create autojump.

Just started reading about autojump on github,interesting project.

Re: “I have [bash] history back to ~2003”

#72

bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and writes its history over the others. So I end-up with never-closing task-based window sessions and occasionally copy-paste commands to a safe file for future reference. I really should investigate the root cause some day...

Frankly the whole system is archaic.

A much better system would be to have a user daemon centralize history (among other things). The benefits would be numerous:

- Better performance

- (optional) Sync between concurrent shells

- No history overwriting problems / race conditions

In addition, this daemon could be used to enable other programs such as autojump. These programs work with the current system, but are based on a hack and as such have needlessly poor performance.

Re: “I have [bash] history back to ~2003”

#73

  $ history | wc -l
  56201
I use a simple prompt_command hook to push my history (from all my machines) to a central MySQL database(https://github.com/fredsmith/history-db). Entries are de-duped and a tally is kept so I can do simple ad-hoc reporting:

  mysql> select * from history order by count DESC limit 10;
  +-------+---------------------+-----------+----------+-------+
  | id    | timestamp           | command   | hostname | count |
  +-------+---------------------+-----------+----------+-------+
  |     1 | 2015-09-02 19:41:45 | ls        | xicada   | 34458 |
  |    89 | 2015-09-02 14:58:33 | cd ..     | xicada   |  4332 |
  |   519 | 2015-08-24 18:38:55 | ll        | xicada   |  3229 |
  |     9 | 2015-09-02 12:37:05 | cd        | xicada   |  2250 |
  |    82 | 2015-08-28 18:27:07 | add       | xicada   |  1887 |
  |   329 | 2015-08-31 18:22:49 | gs        | xicada   |  1817 |
  |    48 | 2015-09-02 19:17:26 | git pull  | xicada   |  1696 |
  |   275 | 2015-08-24 18:23:44 | df -h     | xicada   |  1529 |
  | 15708 | 2013-10-08 01:33:33 | grid unn1 | Europa   |  1210 |
  |    44 | 2015-08-31 13:10:46 | git push  | xicada   |  1139 |
  +-------+---------------------+-----------+----------+-------+
  10 rows in set (0.02 sec)
It's pretty useful (I search through my history constantly with ctrl-R or using bash's history-search-backward hotkeys), and having a 56K line history file doesn't seem to impact history searching or shell startup any noticeable amount.

Re: “I have [bash] history back to ~2003”

#74

bash history had never seemed to work for me between tmux windows. Commands are 'trapped' in their respective window and the last one to close 'wins' and writes its history over the others. So I end-up with never-closing task-based window sessions and occasionally copy-paste commands to a safe file for future reference. I really should investigate the root cause some day...

This is IMHO the real benefit to zsh over bash. You can set zsh to share history between sessions and they are interleaved based on the time the commands were run. No more closing a session in the wrong order and losing half of your history for the day.

Re: “I have [bash] history back to ~2003”

#75
post #25

I wish I had bash history that long. Never seems to have the command I want when I look for it.

I think it's better to simply learn the commands than to have a tremendous amount of history logged. If you have to type a lot of command parameters a lot you can always automate that with aliases anyway.

It's not the stuff you do often that is difficult to remember.

Re: “I have [bash] history back to ~2003”

#76
post #48

Earlier quoted context omitted.

Why?

Why not? I mean, what's the value of knowing you typed 'ls -l' or 'ps -augx' on December 12th, 2012?

The value is in when you remember you did something before, but not exactly how. So you just grep or scan through your history, and the files you edited / commands you ran are likely to refresh your memory even if they don't exactly capture the entire workflow.

Also means you don't have to retype complicated commands too often.

Practical example: I remember I cleaned up some calibre converted epubs with perl a couple months ago, because they had a piece of text injected by some kind of generator on every page. It took me some time to figure out the exact replacement patterns, and if I were to do it again, I just need to do:

$ history 0 | grep perl ... 823 perl -0777 -i.original -pe 's#Generated by ABC Amber LIT Convhttp://www.processtext.com/abclit.html" class="calibre2">erter,

\nhttp://www.processtext.com/abclit.html

\n class="calibre3">##g' part1.xhtml 825 perl -0777 -i.original -pe 's#Generated by ABC Amber LIT Convhttp://www.processtext.com/abclit.html" class="calibre2">erter,

\nhttp://www.processtext.com/abclit.html

\n class="calibre3">##g' *.xhtml ...

Then inspect the history around those commands to find exactly how I got to that point.

Re: “I have [bash] history back to ~2003”

#77
post #48

Earlier quoted context omitted.

Why?

Why not? I mean, what's the value of knowing you typed 'ls -l' or 'ps -augx' on December 12th, 2012?

It's moreso for when you spend time crafting the perfect command, and dont' want to repeat yourlself. Example..

find . -type d -print0 | sort -z | xargs --null -I '{}' du -sh '{}' | sort -h

Simple and clear; but history gives you the convenience to do find and having the command run with out parameter/typo verification.

Re: “I have [bash] history back to ~2003”

#79
post #73

$ history | wc -l 56201 I use a simple prompt_command hook to push my history (from all my machines) to a central MySQL database( https://github.com/fredsmith/history-db ). Entries are de-duped and a tally is kept so I can do simple ad-hoc reporting: mysql> select * from history order by count DESC limit 10; +-------+---------------------+-----------+----------+-------+ | id | timestamp | command | hostname | count |…

I'd be quite interested in someone provided this sort of thing as a SaaS-like drop-in to Bash and Zsh if someone wants a fun weekend project..

Re: “I have [bash] history back to ~2003”

#80
post #79
post #73

$ history | wc -l 56201 I use a simple prompt_command hook to push my history (from all my machines) to a central MySQL database( https://github.com/fredsmith/history-db ). Entries are de-duped and a tally is kept so I can do simple ad-hoc reporting: mysql> select * from history order by count DESC limit 10; +-------+---------------------+-----------+----------+-------+ | id | timestamp | command | hostname | count |…

I'd be quite interested in someone provided this sort of thing as a SaaS-like drop-in to Bash and Zsh if someone wants a fun weekend project..

http://shell-sink.blogspot.com/ used to provide this service - it was what I based my project on.

I'll see what I can do for a hosted/SaaS system this weekend.

Post reply on HN