Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged dig from sorted by
Terminal - Commands tagged dig - 22 results
dig +short which.opendns.com txt @208.67.220.220
2014-02-09 19:24:33
User: dinorox
Functions: dig
Tags: dig dns
15

It's somewhat common ISPs to intercept DNS queries at port 53 and resolve them at their own.

To check if your ISP is intercepting your DNS queries just type this command in the terminal.

"#.abc" it's an OK answer.

But if you get something like "I am not an OpenDNS resolver.", yep, you are beign cheated by your ISP.

dig +short google.com
wki () { dig +short txt "${*// /_}".wp.dg.cx | sed -e 's/^"\(.*\)"$/\1/' -e 's/\([^\]\)"[^\]*"/\1/g' -e 's/\\\(.\)/\1/g' }
2012-05-30 11:36:25
User: kovirobi
Functions: sed
0

This removes the enclosing quotation marks ("), and sticthes the different packets together, e.g. '

for HOSTTOREMOVE in $(dig +short host.domain.tld); do ssh-keygen -qR $HOSTTOREMOVE; done
ssh-keygen -R $(dig +short host.domain.tld)
2012-01-19 15:08:50
User: atoponce
Functions: dig ssh ssh-keygen
2

Quick shortcut if you know the hostname and want to save yourself one step for looking up the IP address separately.

dig +noall +answer exsample.com
timeDNS () { { for x in "${local_DNS}" "208.67.222.222" "208.67.220.220" "198.153.192.1" "198.153.194.1" "156.154.70.1" "156.154.71.1" "8.8.8.8" "8.8.4.4"; do ({ echo -n "$x "; dig @"$x" "$*"|grep Query ; }|sponge &) done ; } | sort -n -k5 ; }
2011-08-18 01:11:53
Functions: dig echo grep sort
0

Evoke from the command like as:

timeDNS commandlinefu.com

.

This isn't too terribly practical, but it is a good code example of using subshells to run the queries in parallel and the use of an "anonymous function" (a/k/a "inline group") to group i/o.

.

I'm assuming you have already defined your local DNS cache as ${local_DNS}, (here, it's 192.168.0.1).

.

You do need to install `moreutils` to get `sponge`.

.

If you're willing to wait, a slower version w/o sponge, (and w/o sorting), is this:

.

DNS () { for x in "192.168.0.1" "208.67.222.222" "208.67.220.220" "198.153.192.1" "198.153.194.1" "156.154.70.1" "156.154.71.1" "8.8.8.8" "8.8.4.4"; do (echo -n "$x "; dig @"$x" "$*"|grep Query) ; done ; }

domain=google.com; for ns in $(whois $domain | awk -F: '/Name Server/{print $2}'); do echo ">>> Nameservers for $domain from $a <<<"; dig @$ns $domain ns +short; echo; done;
2011-05-08 04:46:34
User: laebshade
Functions: awk dig echo whois
1

Change the $domain variable to whichever domain you wish to query.

Works with the majority of whois info; for some that won't, you may have to compromise:

domain=google.com; for a in $(whois $domain | grep "Domain servers in listed order:" --after 3 | grep -v "Domain servers in listed order:"); do echo ">>> Nameservers for $domain from $a

Note that this doesn't work as well as the first one; if they have more than 3 nameservers, it won't hit them all.

As the summary states, this can be useful for making sure the whois nameservers for a domain match the nameserver records (NS records) from the nameservers themselves.

mwiki () { dig +short txt `echo $*|sed 's| *|_|g'`.wp.dg.cx; }
dig +trace google.com
2010-09-03 18:57:29
User: duxklr
Functions: dig
Tags: dig dns
4

Simple command to trace a DNS query from the root all the way to the authoritative servers.

nslookup -q=txt <topic>.wp.dg.cx
dig +short NS org.
curl icanhazip.com
dig +short myip.opendns.com @resolver1.opendns.com
2010-04-02 21:53:26
User: dooblem
Functions: dig
26

Instead of opening your browser, googling "whatismyip"...

Also useful for scripts.

dig can be found in the dnsutils package.

mwiki() { dig +short txt "$*".wp.dg.cx; }
mwiki () { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; }
nslookup {ip}
dig +short -x {ip}
2009-12-21 14:43:35
User: putnamhill
Functions: dig
Tags: IP reverse dig dns
7

The +short option should make dig less chatty.

geo(){ curl -s "http://www.geody.com/geoip.php?ip=$(dig +short $1)"| sed '/^IP:/!d;s/<[^>][^>]*>//g'; }
2009-11-12 17:14:09
User: dennisw
Functions: sed
1

A function that takes a domain name as an argument

check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenavnbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "available" ; fi ; sleep 1 ;done }
2009-09-30 21:17:33
User: xeor
Functions: echo grep sleep
Tags: wget dig dns
0

Mostly for Norwegians, but easily adoptable to others. Very handy if you are brainstorming for a new domainname.

Will only display the available ones..

You can usually do this better with dig, but if you dont have dig, or the TLD only have an online service to check with, this will be usefull..

dig -x 74.125.45.100
2009-09-28 15:13:34
User: postrational
Functions: dig
4

Performs a reverse DNS lookup, variants include:

nslookup 74.125.45.100

or:

host 74.125.45.100
dig +short txt <keyword>.wp.dg.cx
2009-07-31 16:08:59
User: drizzt
Functions: dig
210

Query Wikipedia by issuing a DNS query for a TXT record. The TXT record will also include a short URL to the complete corresponding Wikipedia entry.You can also write a little shell script like:

$ cat wikisole.sh

#!/bin/sh

dig +short txt ${1}.wp.dg.cx

and run it like

./wikisole.sh unix

were your first option ($1) will be used as search term.