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

Query Wikipedia via console over DNS

Terminal - Query Wikipedia via console over DNS
dig +short txt <keyword>.wp.dg.cx
2009-07-31 16:08:59
User: drizzt
Functions: dig
210
Query Wikipedia via console over DNS

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.

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives
mwiki() { dig +short txt "$*".wp.dg.cx; }
2010-03-27 17:54:36
User: dorin
Functions: dig
7

Shorter version, works with multiple words.

mwiki () { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; }
nslookup -q=txt <topic>.wp.dg.cx
mwiki () { dig +short txt `echo $*|sed 's| *|_|g'`.wp.dg.cx; }
wiki() { local IFS=_; dig +short txt "${*^}".wp.dg.cx; }

Know a better way?

If you can do better, submit your command here.

What others think

this is awesomely wacky

Comment by unixx 259 weeks and 5 days ago

Vote this up. One can feel the awesome behind this command :-)

Comment by Alanceil 259 weeks and 4 days ago

cute DNS abuse :)

Comment by penpen 259 weeks and 4 days ago

Very very cool.

Comment by qubyte 259 weeks and 4 days ago

We can add some GUI spice to teh absue :P , dep==> zenity

zenity --info --text="$(dig +short txt $(zenity --entry --title="Search wiki" --text="Enter your search word:").wp.dg.cx)"

Comment by hemanth 259 weeks and 4 days ago

This is simply awesome. In the shell script example, add quotes around the "${1}" and you can do multi-word searches using quotes in your arg, like:

./wikip.sh "gradient descent"
Comment by zombiedeity 259 weeks and 2 days ago

Script with prettified output:

cat wikisole.sh

#!/bin/sh

COLUMNS=`tput cols`

dig +short txt "${1}".wp.dg.cx | sed -e 's/" "//g' -e 's/^"//g' -e 's/"$//g' -e 's/ http:/\n\nhttp:/' | fmt -w $COLUMNS

Comment by philipsd6 259 weeks and 1 day ago

philipsd6's version as a function in bashrc:

function wiki () {

COLUMNS=`tput cols`

dig +short txt ${1}.wp.dg.cx | sed -e 's/" "//g' -e 's/^"//g' -e 's/"$//g' -e 's/ http:/\n\nhttp:/' | fmt -w $COLUMNS

}

Comment by bstaz 259 weeks and 1 day ago

You can also search for more than one word like this:

dig +short txt "multiple words".wp.dg.cx

I wrote a wrapper script that takes either 1 word or multiple words and formulates the syntax properly:

#!/bin/bash

function help {

echo -e "\n\tusage: $0 "

exit

}

if [ -z "$1" ]; then

help

fi

while [ "$1" != "" ]; do

if [ "$SEARCH" = "" ]; then

SEARCH="$1"

else

SEARCH="$SEARCH $1"

fi

shift

done

echo -e "\n\tLooking up $SEARCH\n"

dig +short txt "$SEARCH".wp.dg.cx

echo ""

Comment by omish_man 259 weeks and 1 day ago

I hate dig.

Why not use:

host -t txt linux.wp.dg.cx
Comment by vutcovici 259 weeks ago

Simpler multiple words fix:

dig +short txt "`echo $@`".wp.dg.cx

Comment by peter0081 254 weeks and 5 days ago
dig +short txt <keyword>.wp.dg.cx | espeak
Comment by matthewbauer 252 weeks and 4 days ago

I wonder if we can do that with French language ( fr.wikipedia.org )

Like with this example : fr.wikipedia.org/wiki/Tse

Comment by sputnick 238 weeks and 3 days ago

OOps, http://fr.wikipedia.org/wiki/Services_de_terminal

Comment by sputnick 238 weeks and 3 days ago
mwiki () { echo $@ > foo; blah=`sed 's/ /_/g' foo`; dig +short txt $blah.wp.dg.cx; }

Sample output:

mwiki snow leopard

"The snow leopard (Uncia uncia or Panthera uncia), sometimes known as \"ounce,\" is a moderately large cat native to the mountain ranges of Central Asia. The classification of this species has been subject to change and its exact taxonomic position is still " "unclear.

Comment by oshazard 235 weeks and 6 days ago

#! /bin/bash

echo please input your subject

read SUBJECT

dig +short txt SUBJECT.wp.dg.cx

Comment by ethnopunk 226 weeks and 5 days ago

Shorter version, works with multiple words:

mwiki() { dig +short txt "$*".wp.dg.cx; }

Comment by dorin 225 weeks and 4 days ago

on windows:

nslookup -q=txt shit.wp.dg.cx
Comment by unixmonkey9108 225 weeks ago

"slookup -q=txt" does not appear to be valid (i have WinXP+SP3)...

Comment by bugmenot 205 weeks and 1 day ago

sorry, in mean "Nslookup -q=txt"...

Comment by bugmenot 205 weeks and 1 day ago

Nice. These dns lookups seems faster than an actual http request.

But I don't like the disturbing " and \ and the missing linebreaks. Therefore by combining dorin's ID with a sed and fmt I get to:

mwiki() { dig +short txt $(echo $* | sed 's/ /_/g').wp.dg.cx|sed -E "s/\" \"|^\"|\"$|\\\\//g"|fmt; }
Comment by unixmonkey12820 197 weeks and 4 days ago

what do you need this for?

has it some advantages to to such a query over DNS?

why can't you use curl instead?

Comment by rubo77 196 weeks and 1 day ago

how to convert the utf-8 encode result to itf-8?

e.g. when I query "Leon", I got "L\195\169on".

I tried to convert is using "echo -e", but echo only support \xC3\xA9 format.

Comment by hileon 101 weeks and 6 days ago

This command is great.

But when I run it now I get:

;; connection timed out; no servers could be reached

Anyone know what's wrong? I looks like Wikipedia is blocking dns requests or something else has changed.

Comment by JokesOnYou 76 weeks and 5 days ago

JokesOnYou ... not sure exactly but you can stipulate the nameserver to query as a swich to dig, ie (using opendns).

dig @resolver1.opendns.com +short txt "${1}".wp.dg.cx

Comment by khayyam 69 weeks and 6 days ago

But does this work?~

Comment by ohuhu 34 weeks ago

I mean how does this work

Comment by ohuhu 34 weeks ago

The guy who made it possible: https://dgl.cx/wikipedia-dns

@sputnick Like said in the link above, this is a special nameserver that returns a short description of the query. So the article language is handled at server side.

Comment by dinorox 23 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts