See also the shell code page for more general tips.
Bash completion
No Bash without Bash completion. :-) Make sure you have something like this in your non-superuser .bashrc files:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
I find it to be slow at this point (takes maybe 5 seconds to load on a decent machine, hmm… so you want not to have it in /root/.bashrc but instead use sudo where you can) but very useful. apt*, dpkg*, file type recognition for lots of commands, etc. etc. Saves a lot of time.
If you know what to write, you can add your own completions in ~/.bash_completion .
History search
Bash, just like Zsh in this respect, "blocks" forward search history as it's set to Ctrl-s by default. I recommend changing the Bash setting rather than anything else.
To do this, try putting this in ~/.inputrc :
$if Bash
"\er": forward-search-history
$endif
(That is, Alt-r.)
Notes:
- Zsh does not (AFAIK) read any inputrc or .inputrc file, see the Zsh page for instructions in that case.
- You'll probably have to restart Bash for changes to take effect. While you could try bind -f ~/.inputrc , this may leave old settings behind.
- /etc/inputrc does not seem to be queried by Bash for some reason. You'd have to edit some appropriate file, such as /etc/bash.bashrc, or maybe /etc/profile since /etc/inputrc can be used not just for Bash. In any case, try setting the INPUTRC environment variable. However, it would seem ~/.inputrc is not read then… 1
In the end you may want to enter keybindings directly into your respective Bash configuration files. The syntax here becomes a bit different because of escapes etc. After some minutes of trying I came up with this as an equivalent of the above .inputrc file:
bind '"\er": forward-search-history'
Basically, take a line that you would use in the .inputrc file, and insulate it with single quotes. (If it has single quotes in it, escape those with a backslash.) Without that insulation, I have no idea how to write that line - I tried quite a few variations.
$ bind -P | grep "^forward-s"
forward-search-history can be found on "\C-s", "\er".
$ bind -P | grep "^reverse-s"
reverse-search-history can be found on "\C-r".
1 One way to test this is to 1) open a shell 2) touch the files you want to track 3) start Bash from the shell you just opened 4) stat the files and see if the access time changed. (Note that Bash does not seem to open a file if its size is 0.)
More Bash configuration
In ~/.bashrc :
setterm -bfreq 0 # no PC speaker sounds or similar ;-)
set -P # no symlink insanity! After doing a cd <symlink> the real path will be displayed.
I previously suggested set -b as well, since it might be confusing to get a "Done" message after the next command. However, set -b gives us an even more distracting situation, e.g.:
$ echo foobar &
[1] 12217
foobar
$ [1]+ Done echo foobar
which looks ugly and is a little confusing (since the text after the prompt isn't actually related to it at all).
For more alias(es), see also recursive type command.