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 translate from sorted by
Terminal - Commands tagged translate - 9 results
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
2
translate some text

Change lang from ru to something else.

leo() { lang=en; IFS=+; Q="${*// /%20}"; curl -s "https://dict.leo.org/${lang}de/?search=${Q//+/%20}" | html2text | grep -EA 900 '^\*{5} ' | grep -B 900 '^Weitere Aktionen$';}
2013-06-24 22:35:46
User: michelsberg
Functions: grep
4

Translate strings from non-german to german (and vice versa) using LEO. Put it in your ~/.bashrc.

Usage:

leo words

To support languages other than english, change the lang variable:

lang=ch # chinese

lang=en # english

lang=es # spanish

lang=fr # french

lang=it # italian

lang=pl # polish

lang=pt # portuguese

lang=ru # russian

The other language will always be german!

tr a-z A-Z < file.txt
function say { mplayer -really-quiet "http://translate.google.com/translate_tts?tl=en&q=$1"; }
2011-12-16 20:56:40
User: tikal808
0

Put the string above in your ~/.bashrc or ~/.bash_profile, then source the file. Make sure your sound output is working, you have mplayer installed, then type in a word or sentence similar to below:

say "why won't anyone talk to me?"

It's easy to get the language to be different by changing the "en" in the string to be "de" or some other language that Google Translate supports. Have multiple "say" functions, like "say-en" "say-de", etc.

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
5

substitute "example" with desired string;

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

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

tw translate.google.com.de-en `xsel`
2010-06-11 22:28:28
User: dbbolton
-1

Translate the X selection from German to English. The tw program is available from Savannah: http://mirror.its.uidaho.edu/pub/savannah/twandgtw/

I'm posting this because the base Debian system also does not include curl.

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/'; }
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

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
61

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