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

Just as useful,

history | grep pattern

With all the useful grep abilities (like peaking at commands before or after the given pattern).



sort by: page size:

Yep, I do `history | grep "<whatever>"` all the time..

I should probably make it a function now that I think about it.


history | grep <command halfway remember using>

history | grep in regular bash

Also, another way to find past commands you run `history | grep <whatever-you-are-looking-for>` and works wonders; or as other users have mentioned, Ctrl-R works too.

history | grep <thing>

I use a number of tools and I've often forgotten an individual command, or when I'm using tools like curl or docker that have a long single line command that I know I can't remember.


I usually do a `history | grep something | grep somethingelse` to find stuff in my history

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.

I alias "history | grep" to "hrep" and I'd bet it is one of my top 3-5 commands.

    history | grep <keyword>
I use this for <keyword> rsync or rdesktop when I have forgotten the long list of options & directories etc

I also use ctrl R <keyword> at the bash prompt but that only gives me the most recent match.


This would not allow me to

1) start typing a command;

2) look at or copy+paste stuff from the previous commands

I usually do my history search through history|grep.


I have a very common use case. I have had old machines that I have had to recreate or upgrade from scrach, and the shell history is instrumental in supporting this.

just a simple example:

  history | grep pacman

I use these two commands regularly:

1. `history | grep somecommand` to see a command I used previously. (I have my history set to a bonkers high number.) 2. `curl cht.sh/somecommand` to see a crowdsourced cheatsheet for a command. See: https://cht.sh/grep 3. DuckDuckGo often has good cheat sheets, e.g. https://duckduckgo.com/?q=tmux+cheat

I also use fish, which has nice history-based autocomplete


I usually just do `history | grep ...` instead; it's faster and more flexible than trying to flip through Ctrl+R matches.

That said, I did just install the history-search-backward and history-search-forward hooks in inputrc, and I can already tell I'll love these.


As someone above said,

history | grep -i "whatever I want to remember"


A long time ago I set my history file to save up to the previous 1000 commands, and I ended up mostly learning grep for the first time because I wanted to search quickly for various recent commands. Stuff like "history | grep _some ip_" or things like that.

Storing the entire history would no doubt be helpful, but I feel similarly to what other people have said so far, which is that it may not be the safest thing to do? Probably depends on usecase.


For something more rustic, an .inputrc file with this:

    # history-search-backward / history-search-forward bound to the up and down arrows
    "\e[A": history-search-backward
    "\e[B": history-search-forward
    "\e[C": forward-char
    "\e[D": backward-char
    set show-all-if-ambiguous on
    set completion-ignore-case on 
Will search through anything matching what you've already entered. Type something like "gr" and scroll up or down to see all your previously used grep commands. Saw this long ago on here and it's on every machine I use now, can't live without it. Thankyou to whoever originally posted it.

shell command line history roll your own: fn history {grep '^term%' /mnt/wsys/text|sed -e 's/^term%//'}

oh yes that is so elegant...


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

I often find myself remembering commands or parts of commands before or after the command I need. Now I can write a one off awk or perl script to parse history output, but I haven't gotten around to making a general tool.
next

Legal | privacy