Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Also bash has a built-in incremental history search.

http://www.gnu.org/software/bash/manual/bashref.html#Searchi...



sort by: page size:

I like this. It looks like a much better fleshed out version of a one-off python script I use to search bash history - it even coincidentally has the same name so it'll fit right into the muscle memory :D

https://stackoverflow.com/questions/43019250/made-quick-scri...


In case you didn't know, bash has a basic version of this already embedded. You can search your bash history from the command line with Control+R (not Cmd+R even for Macs).

Probably the most useful thing I've done regarding bash history: https://eli.thegreenplace.net/2016/persistent-history-in-bas...

Thanks, I didn’t know that! I use the fish shell, which does history searching differently but this is useful for those few times when I’m in bash.

> you can do ctrl + r to achieve the same thing.

C-r will (usually?) invoke reverse-search-history (http://www.gnu.org/software/bash/manual/html_node/Commands-F...) in bash (and I'm sure some other shells also).


Bash can do that, with Ctrl-r. Press Ctrl-r, then type beginning of command, then press Ctrl-r repeatedly to go back through history.

https://www.digitalocean.com/community/tutorials/how-to-use-...

That page also deals with stuff like getting bash not to delete history with each session, so searching history can be more useful.


I'm using a variant of this: https://spin.atomicobject.com/2016/05/28/log-bash-history/

Logging the entire bash history in files sorted by day: export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'

I haven't overloaded ctrl-r yet to search in these files but that would be a possibility.


I use fasd: Its the best bash tool out there. Jump, search the previous history based on frequency of usage. It updates your search with its algorithm matching the most predicted one.

https://github.com/clvv/fasd

worth mentioning, nothing comes close this one.


bash has a history search feature you can access via control-r.

Meh. I prefer to leverage SQL.

I have yet to find a better way to store and search bash history than:

https://github.com/tkf/rash

More recent bash sqlite history attempts all seem to fall short than this implementation, they store less metrics or have other caveats.


The feature I use the most is automatic history search by typing part of a command and hitting UP to search the history.

Doesn't bash have that same feature? Or is there some subtle difference between what you're describing and what bash does?


Actually, after hitting C-R <keyword>, you can keep pressing C-R to search backwards through the history. Or C-S to search forwards. More info: (bash uses emacs editing mode by default) http://www.gnu.org/software/emacs/manual/html_node/emacs/Bas...

Your machine probably has ^r for working through bash history

But that aside, if you’re into arrow pressing, a few lines in your .inputrc can go a long ways

Test this out sometime:

  # Incremental searching with Up and Down and Left and Right
  "\e[A": history-search-backward
  "\e[B": history-search-forward
Now you can type “find” and press up/down arrow to just cycle through history that starts with find

I use an eternal history setup for bash, with bash session tags that let me sort history by tag for correct backward-search behavior.

(edit) Not to imply this functionality belongs to a terminal, far from it. But it's nice to have access to 2 years of shell commands :-)


Not quite a command, but ctrl+r in bash does a real useful history search

Just use Ctrl-R in bash to search backwards in the history

Thanks for the link! I've been looking for a writeup on bash history features for a while. These things are very useful day-to-day.

I just want to throw in that you can get that nice up-arrow-history in bash too. It's the first thing I put in a new bash environment:

  bind '"\e[A":history-search-backward'
  bind '"\e[B":history-search-forward'

I came here to say this. In addition, searching through bash history is a terrible "save and fetch" interface
next

Legal | privacy