Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTerm2 get previous DIFFERENT command using up and down arrow keys

I found it irritating that if you run one command 5 times you have to press the arrow key 6 times to get the previous command. Is it some way to change this behavior?

iTerm2 Build 1.0.0.20111020

like image 745
bandola Avatar asked Jan 15 '12 22:01

bandola


People also ask

How do I get past command in terminal?

1) Ctrl + P This is the most dependable shortcut in Linux to execute the last run command in the terminal. Just press the Ctrl and P keys together to fill the prompt with the last executed command and you are ready to go.

Which key is used to reuse the previous command?

For example, most of us know that we can press Ctrl-p (or the Up-Arrow key) to recall the last command so that we can modify it and press Enter to execute it.

How do I find previous commands in Unix?

Using a Reverse Search of Linux Command History To enter this mode you simply press ctrl and r. You can then enter a search term and use repeat presses of ctrl and r to step back through the list of previous commands containing that term.

How do I run a previous version of a terminal in Mac?

Repeat previously entered commands In the Terminal app on your Mac, press the Up Arrow key. The last command you entered appears on the command line. Continue pressing the Up Arrow key until you see the command you want, then press Return.


1 Answers

That's not a feature of iTerm but of your shell's history feature. If you use the default Bash you can put this into your ~/.bashrc:

export HISTCONTROL=ignoreboth
shopt -s histappend
# After each command, save and reload history
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

The first line will tell Bash to ignore duplicated and empty history entries. The second line will merge the history of multiple open sessions (e.g. in multiple tabs or windows). The thirs line will make sure that the history is preserved after each command.

like image 71
Holger Just Avatar answered Nov 15 '22 06:11

Holger Just