We all know how to use <ctrl>-R to reverse search through history, but did you know you can use <ctrl>-S to forward search if you set stty stop ''? Also, have you ever tried running bind -p to see all of your keyboard shortcuts listed? There are over 455 on Mac OS X by default.
What is your single most favorite obscure trick, keyboard shortcut or shopt configuration using bash?
When running commands, sometimes I’ll want to run a command with the previous ones arguments. To do that, you can use this shortcut:
Occasionally, in lieu of using find, I’ll break-out a one-line loop if I need to run a bunch of commands on a list of files.
Configuring the command-line history options in my .bash_login (or .bashrc) is really useful. The following is a cadre of settings that I use on my Macbook Pro.
Setting the following makes bash erase duplicate commands in your history:
I also jack my history size up pretty high too. Why not? It doesn’t seem to slow anything down on today’s microprocessors.
Another thing that I do is ignore some commands from my history. No need to remember the exit command.
You definitely want to set histappend. Otherwise, bash overwrites your history when you exit.
Another option that I use is cmdhist. This lets you save multi-line commands to the history as one command.
Finally, on Mac OS X (if you’re not using vi mode), you’ll want to reset <CTRL>-S from being scroll stop. This prevents bash from being able to interpret it as forward search.