Read
more on "Tips of the Trade" »
Hitting tab to complete commands and filenames is great. Extending this to hostnames is even better. (Does it show that I'm very lazy?) One way of doing this is to switch to the zsh shell, which does this and a bunch of other stuff by default. Happily, though, if you'd rather stick with
bash, all is not lost.
(path on a Mac is /opt/local/etc/bash_completion). Add this to your
~/.bashrc or ~/.bash_profile to load it automatically on
startup. Now, try typing ssh and a couple of letters of a machine
you often ssh to, then hit Tab. Bingo! You'll get either a list of options,
or, if there's only one option available, the name filled in, just like with
the tab-completion you're already used to.
and you should now be able to tab-complete hosts with that, as well. (If you
have problems, try specifying its full path.)
Read more on "Tips of the Trade" »
Host Completion in bash
![]() |
bash has programmable parameter completion, so you could set hostname completion up by coding it yourself. That's not necessary, though. Instead, you can pick up the bash completion files (also available as the bash-completion package in RH, Debian and from Darwin Ports for Mac OS X).
Once you've installed that, type:
. /etc/bash_completion |
|
Recent Tips » More Fun With ssh » Keeping Your ssh Connection Alive » 3 Apache/httpd Command-Line Options Read All Tips of the Trade |
This takes information from your .ssh/known_hosts file. It works automatically for ssh and similar commands, but you can also set other commands to use it. For example, maybe you have a script called 'update' which updates a particular host. Type:
complete -F _known_hosts update |
To investigate programmable completion options more, complete -p will list all the currently available completions.
Page
1 of
1
Read more on "Tips of the Trade" »
0 Comments (click to add your comment)
Networking Solutions


Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.