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.

World cup college
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

2010-03-18 - Top 10 commands explained
There's a great article by Peteris Krumins explaining the current top 10 commands: http://www.catonmat.net/blog/top-ten-one-liners-from-commandlinefu-explained/
2010-03-03 - Commandlinefu @ SXSW 2010
Am going to be at SXSW this year, in case you want to submit any CLI nuggets or suggestions to me in person. Ping me on the @codeinthehole Twitter account.
2009-09-12 - Email updates now available
You can now enable email updates to let you know each time you're command is commented on.
2009-07-11 - API and javascript blog widget now available
A simple API has been released, allowing commands to be retrieved in various formats. This also allows commands to be embedded on blogs/homepages.
Hide

Tags

Hide

Functions

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
37
Google Translate

Usage:

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

Example:

translate hello en es

See this for a list of language codes:

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

Alternatives

There are 2 alternatives - 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
7

allow multiword translations

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
2
translate <phrase> <source-language> <output-language>

works from command line

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 25 weeks and 3 days 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 25 weeks and 2 days 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 25 weeks and 2 days 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 25 weeks and 2 days 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 25 weeks and 2 days ago

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

Comment by fab4am 25 weeks and 2 days ago

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

Comment by kjowens 22 weeks and 4 days ago

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

Comment by matthewbauer 22 weeks and 4 days ago

Your point of view

You must be signed in to comment.

Related sites and podcasts