Comment by elSidCampeador

4 years ago

same here - my cheatsheet is `history | grep`

I'm curious why history | grep and not ctrl-R?

  • Probably because ctrl-R doesn't present you a list in most shells. Maybe you want to scan the list visually and look at neighboring commands. ctrl-R doesn't really take advantage of human vision by showing all results next to each other.

    • That's pretty much it. I used to have to use quite a few different shells, so `<CTRL> + r` wasn't always available, but `history | grep` usually was. Once I'd got in the the habit of using `history | grep` I found that I liked the extra context provided by seeing a group of commands with a few variations between the lines. So often it helps jog my memory of what parameters I'll need to change before using it.

    • Agreed on the value of the list. I additionally dedupe as follows:

      H() { history | egrep -v '^ *[[:digit:]]+ +H +' | grep "$@" | sort -rk 2 | uniq -f 1 | sort; }

    • For me that’s it indeed; grep, sometimes with -A -B is much faster in general for me because it might be similar commands which now will appear next to eachother.

  • Regular expressions. Sometimes you remember two non-adjacent parts. Ctrl-R doesn't let you find "when I used find with awk" unless you type in everything in between.