Extract shortcuts and hostnames from .ssh/config

awk '$1=="Host"{$1="";H=substr($0,2)};$1=="HostName"{print H,"$",$2}' ~/.ssh/config | column -s '$' -t
Spits out table that shows your Host->HostName aliases in ~/.ssh/config

3
By: wejn
2014-05-24 20:51:47

These Might Interest You

  • Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. A slightly shorter version.


    2
    cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s ' ' | sed 's/^\s//' | cut -d ' ' -f 2 | sed 's/www.//' | sort | uniq
    chronosMark · 2010-04-08 15:50:34 0
  • Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server. When i saw the command i had some ideas to make it shorter. Here is my version.


    0
    egrep 'ServerAlias|ServerName' /etc/apache2/sites-enabled/*.conf | awk '{printf "%s\t%s\n",$2,$3}' | sed 's/www.//' | sort | uniq
    staeff · 2012-07-25 12:51:15 0
  • Get a list of all the unique hostnames from the apache configuration files. Handy to see what sites are running on a server.


    0
    cat /etc/apache2/sites-enabled/* | egrep 'ServerAlias|ServerName' | tr -s " " | sed 's/^[ ]//g' | uniq | cut -d ' ' -f 2 | sed 's/www.//g' | sort | uniq
    chronosMark · 2010-04-08 08:51:17 1
  • This is a multi-sourced hostname tab completion command you can put in your .bashrc (or your .bash_profile on a MAC). This will not only your .ssh/config, it will parse ALL of the following files for hostnames: .ssh/config .ssh/known_hosts .bash_history (I realize this could be prettied up by defining and calling the function, instead of implicitly referencing it, but this was more breif) Show Sample Output


    0
    complete -W "$( { awk '/^Host / { print $2 }' ~/.ssh/config | egrep -v '\*|,' echo $( grep '^ssh ' .bash_history | sort -u | sed 's/^ssh //' ) while IFS=' ,' read host t; do echo $host; done < ~/.ssh/known_hosts ;} )" ssh
    thelinuxgirl · 2012-02-28 18:08:53 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: