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

Good idea, but you shouldn't overwrite ctrl-O, which is a wildly useful function in bash: run current command in history and retrieve the next. If you want to re-run a sequence of several history commands, you can find the first in history (such as via ctrl-R reverse-isearch), then repeatedly hit ctrl-O to run it and retrieve the next command from history.


sort by: page size:

My favorite bash trick is still Ctrl-O: submit command and advance history by one.

If you ever find yourself counting up-arrows to repeat a sequence of commands (that aren't worth scripting for whatever reason), next time, go to the top of the list and hit Ctrl-O. The result is the the command runs, and the one after it in the history is loaded into you prompt.


In many bash configurations, ctrl-o is bound to 'operate-and-get-next’. If you hit up 20x, you should then be able to hit ctrl-o to run that command, and your history will automatically go to the next command down. Check it out, it’s great!

EDIT: beaten by pm215!


In addition, I think bash's `operate-and-get-next` can be very helpful. When you go back through your shell history, you can hit Ctrl+o instead of enter and it will execute the command then put the next one in your history on the command line, and keep track of where you are in your history. This way, you can rerun a bunch of commands by going to the first one and Ctrl+o till you are done. And you can edit those commands and hit Ctrl+o and still go to the next previously run command.

Note: fzf's history search feature breaks this. https://github.com/junegunn/fzf/issues/2399

Edit: And up and down will still keep the relative position you are at in your history in case you want to skip a command.


"In bash, use Ctrl-R to search through command history."

Or, add these lines to your .bashrc to use Ctrl-p and Ctrl-n:

bind "\C-p":history-search-backward

bind "\C-n":history-search-forward


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've noted once within my personal bash cheat sheet this:

Search the command history

* Search as you type: Ctrl + r and type the search term; Repeat Ctrl + r to loop through results.

* Search the last remembered search term: Ctrl + r twice.

* End the search at current history entry: Ctrl + j

* Cancel the search and restore original line: Ctrl + g

Try of course at your own risk. But works for me.


I learnt something handy in BASH recently - operate-and-get-next (Ctrl-o). If you type:

  $ echo one
  one
  $ echo two
  two
  $ echo three
  three
Then up-arrow back to 'echo one'. Then press Ctrl-o instead of enter it will execute the command and display the following one in your history ('echo two' in this case).

Very handy for replaying a series of commands.

http://www.faqs.org/docs/bashman/bashref_101.html


Looks like this doesn't support Ctrl-O (run line and retrieve next line from history). I've found that incredibly useful for re-running a series of commands: Ctrl-R to reverse search, type a few letters, Ctrl-O Ctrl-O Ctrl-O.

Thanks, I discovered C-o thanks to you (even though I have gone through the bash manual several times).

No, more having to press C-r multiple times just to get sequential group of commands from history.


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

Instead of aliasing common commands, I make heavy use of Ctrl-r at the command prompt to search the history.

So if I have a complex command I want to run several times, I'll type it out in full the first time. After that, I'll hit Ctrl-r and start typing part of the command until it shows the one I mean, then hit enter to run it.


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.

Better yet, just set your history to 10k-20k+ items and use reverse-search (ie. Ctrl+r in bash) to recall your old commands. Navigation aside, about 80-90% of commands I use regularly are already in the shell history.

I use ctrl-P/N for history-beginning-search-{backward,forward} in Zsh. Type the start of a previous command and cycle through the matches.

Last year a friend taught me about the bash trick "CTRL-R" <start typing 'ssh' or some other previously run command> on the command line for reverse history searching, and it is an amazing time saver. It acts as a great alternative to #8, "Find the last command that begins with “whatever,” but avoid running it"

$ !whatever:p


Example:

Tip: Bash reverse search, because manually scrolling through your history is a nuisance.

How (OS X): CTRL+R, start typing a word from your command history. Press CTRL+R to cycle through matches, ENTER to execute, TAB to edit. If you want to add forward search to bash, you can re-map your key bindings in your bash profile with the following (maps to CTRL+T): bind "\C-t":forward-search-history


When dealing with bash history, I find that too many people are still unaware of C-r (Ctrl+R or Command+R): press it and start typing unique bits of your past commands. If multiple commands match, cycle through them with repeated C-r presses.

The usual reaction is :mindblown: :)


My biggest problem with it is it breaks operate-and-get-next (Ctrl+O). So I still have to manually walk back in my history if I want to rerun a sequence of commands.

> operate-and-get-next (C-o)

> Accept the current line for execution and fetch the next line relative to the current line from the history for editing. A numeric argument, if supplied, specifies the history entry to use instead of the current line.

next

Legal | privacy