Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When you say “eternal bash history” how long is that? I thought after some large number it becomes very slow. I’d like to try this if you don’t mind sharing how you did that?


Not parent poster, but I use zsh-histdb [0] to keep my history in an SQLite database.

There is also Historian [1] for bash, and a bunch of other suggestions in the discussion thread on it on HN [2]

[0]: https://github.com/larkery/zsh-histdb

[1]: https://undertitled.com/2017/04/12/historian-because-please-...

[2]: https://news.ycombinator.com/item?id=14103688


I have a script that removes duplicates and HISTIGNORE set to ignore simple commands like cp, ls, mv, mkdir etc. In the past 5 years I've only executed around 20k unique commands using up around 900kb.


> Not parent poster, but I use zsh-histdb [0] to keep my history in an SQLite database

Why? A file is easier to grep (even if you have to pass `-a` to it after the file starts to be in the MBs, right now it is 7.4MB). I love having eternal command history in my zsh, and I wonder if I miss something out by not using SQLite for this.


My bash history is currently with 12MB, not slow at all.

I use this format:

  HISTTIMEFORMAT="[%F %T] "
  HISTFILESIZE=1000000000
  HISTSIZE=10000000
  readonly HISTTIMEFORMAT
  readonly HISTFILESIZE
  readonly HISTSIZE
  export HISTTIMEFORMAT
  export HISTFILESIZE
  export HISTSIZE
  # To always append, never overwrite history
  shopt -s histappend

So I get this output:

  <SEQ> [2020-02-09 07:18:30] <COMMAND>


I'm up to about 4 years of history at this point. I use a dumb bash hook that sorts and reloads the history on each command execution, and yes, it's getting a little slow. I wish I could do this through some daemon-based DB-backed system but this works for now. Maybe I'll switch to zsh when it gets too slow.

The reason I have the hook reload and sort on each command is so that I can use a dozen screen sessions at once and:

1) they don't overwrite each other's history

2) each session's history is instantly searchable to the others

3) sorting is useful because each session prepends a session ID to the commands, so that Ctrl-R backward search can always hit the current session's commands first. And I can reboot/restart screen and recover history in each session.

(edit: I looked at the zsh-db project the other poster linked, and this does pretty much the same thing just probably slower since there is no DB involved).


I push every unique command that I type into a database and bind Ctrl-R to peco querying the 10k commands. I'm amazed it did not occur to me earlier. All of my systems have access to the same shared history, which greatly simplifies multi window and multi computer operations.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: