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.
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.
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 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.
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
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.
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.
history | grep pattern
With all the useful grep abilities (like peaking at commands before or after the given pattern).
reply