Hostname Completion

Courtesy of Pete in work. To enable hostname auto completion in Bash, do the following:

dig pop @dns.server.tld axfr | awk '$4 ~ /\yA\y/ && gsub(/.$/,"",$1) {print $1}' > ~/.hosts

If you would prefer to filter out hosts e.g. dev and swi, change awk to:

awk '$4 ~ /\yA\y/ && ! /dev/ && ! /swi/ && gsub(/.$/,"",$1) {print $1}'

Add the following to ~/.bashrc on linux:

export HOSTFILE=$HOME/.hosts complete -A hostname -o default dig host ping netcat curl ssh

Open a new terminal or source bash_profile, you should now be able to tab complete hostnames.

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">