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
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With