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.

Universal configuration monitoring and system of record for IT.

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:



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.

Top Tags



Google Translate

Terminal - Google Translate
translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
2010-03-08 03:15:48
User: matthewbauer
Functions: sed wget
Google Translate


translate <phrase> <source-language> <output-language>


translate hello en es

See this for a list of language codes:



There is 1 alternative - vote for the best!

Terminal - Alternatives
translate() { lng1="$1";lng2="$2";shift;shift; wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=${@// /+}&langpair=$lng1|$lng2" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; }
2010-05-02 22:15:30
User: bandie91
Functions: sed wget

allow multiword translations

wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=translation+example&sl=auto&tl=fr" | sed 's/\[\[\[\"//' | cut -d \" -f 1
2011-03-06 13:46:16
User: sairon
Functions: cut sed wget

substitute "example" with desired string;

tl = target language (en, fr, de, hu, ...);

you can leave sl parameter as-is (autodetection works fine)

cmd=$( wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=$2|${3:-en}" | sed 's/.*"translatedText":"\([^"]*\)".*}/\1\n/'; ); echo "$cmd"
2010-03-13 01:09:00
User: dtolj
Functions: sed wget
translate <phrase> <source-language> <output-language>

works from command line

curl -s -A "Mozilla" "http://translate.google.com.br/translate_a/t?client=t&text=Hi+world&hl=pt-BR&sl=en&tl=pt&multires=1&ssel=0&tsel=0&sc=1" | awk -F'"' '{print $2}'
2011-07-03 00:11:52
User: gean01
Functions: awk

Translates a string from English to Portuguese by using google translator web service.

translate () {lang="ru"; text=$*; wget -U "Mozilla/5.0" -qO - "http://translate.google.com/translate_a/t?client=t&text=$text&sl=auto&tl=$lang" | sed 's/\[\[\[\"//' | cut -d \" -f 1}
2014-06-10 12:08:51
User: klisanor
Functions: cut sed wget
translate some text

Change lang from ru to something else.

Know a better way?

If you can do better, submit your command here.

What others think

See https://redmine.sputnick-area.net/projects/show/polytranslator

Comment by sputnick 268 weeks ago

Also try:

translate(){ curl -s "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hi&langpair=$(curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$1" | sed 's/.*"language":"\([^"]*\)".*/\1^C/')%7C$2" | sed 's/.*{"translatedText":"\([^"]*\)".*/\1\n/'

Will fetch the source language for you.

Comment by matthewbauer 268 weeks ago
translate(){ curl -s "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hi&langpair=$(curl -s "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=$1" | sed 's/.*"language":"\([^"]*\)".*/\1^C/')%7C$2" | sed 's/.*{"translatedText":"\([^"]*\)".*/\1\n/'; }
Comment by matthewbauer 268 weeks ago

Actually, if you leave the source language blank, it will guess it anyway and it's normally pretty successful. Also, you can have the command translate to English if you don't provide a language to translate to by using a default value for the second parameter, like this:

translate(){ wget -qO- "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$1&langpair=%7C${2:-en}" | sed 's/.*{"translatedText":"\([^"]*\)".*/\1\n/'; }
Comment by eightmillion 268 weeks ago

In bash it doesn't work with spaces or accentuated letters (in french for example). This one does it (accentuated, bash working, and guessing source language if not provided) :

translate(){ curl -s "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=`perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$1"`&langpair=`if [ "$3" != "" ]; then echo $2; fi;`%7C`if [ "$3" == "" ]; then echo $2; else echo $3; fi;`" | sed 's/{"responseData": {"translatedText":"\([^"]*\)".*}, .*}/\1\n/'; }
Comment by fab4am 267 weeks and 6 days ago

ok the wget one seems to work too with spaces and accents

Comment by fab4am 267 weeks and 6 days ago

how do you know the abbreviations for languages? link please.

Comment by kjowens 265 weeks and 2 days ago

See: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Comment by matthewbauer 265 weeks and 2 days ago

{"responseData": null, "responseDetails": "Suspected Terms of Service Abuse. Please see

Comment by vp_arth 77 weeks and 4 days ago


"responseData": null,

"responseDetails": "Suspected Terms of Service Abuse. Please see code.google.com/apis/errors",

"responseStatus": 403


Comment by vp_arth 77 weeks and 4 days ago

Your point of view

You must be signed in to comment.