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.


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.




Commands tagged google from sorted by
Terminal - Commands tagged google - 54 results
t2s() { wget -q -U Mozilla -O $(tr ' ' _ <<< "$1"| cut -b 1-15).mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=$(tr ' ' + <<< "$1")"; }
2013-10-16 23:29:59
User: snipertyler
Functions: cut tr wget

Usage: t2s 'How are you?'

Nice because it automatically names the mp3 file up to 15 characters

google() { gg="https://www.google.com/search?q=";q="";if [[ $1 ]]; then for arg in "$@" ; do q="$q+$arg"; done ; if [[ -f /usr/bin/chromium ]]; then chromium "$gg"$q; else firefox -new-tab "$gg"$q; fi else echo 'Usage: google "[seach term]"'; fi }
google() { gg="https://www.google.com/search?q="; ff="firefox"; if [[ $1 ]]; then "$ff" -new-tab "$gg"$(echo ${1//[^a-zA-Z0-9]/+}); else echo 'Usage: google "[seach term]"'; fi }
2013-08-01 22:21:53
User: lowjax
Functions: echo

Usage: google "[search string]"

Example: google "something im searching for"

This will launch firefox and execute a google search in a new tab with the provided search string.

You must provide the path to your Firefox binary if using cygwin to $ff or create an alias like follows:

alias firefox='/cygdrive/c/Program Files (x86)/Mozilla Firefox/firefox.exe'

Most Linux flavors with Firefox installed will use just ff="firefox" and even OSX.

function google { Q="$@"; GOOG_URL='https://www.google.de/search?tbs=li:1&q='; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}${Q//\ /+}" | grep -oP '\/url\?q=.+?&amp' | sed 's|/url?q=||; s|&amp||'); echo -e "${stream//\%/\x}"; }
2013-04-05 08:04:15
User: michelsberg
Functions: echo grep sed
Tags: google

Put it in your ~/.bashrc


google word1 word2 word3...

google '"this search gets quoted"'

Q="YOURSEARCH"; GOOG_URL="http://www.google.com/search?q="; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}\"${Q/\ /+}\"" | grep -oP '\/url\?q=.+?&amp' | sed 's/\/url?q=//;s/&amp//'); echo -e "${stream//\%/\x}"
2013-04-03 09:56:41
User: techie
Functions: echo grep sed
Tags: google

I found this command on a different site and thought you guy might enjoy it. Just change "YOURSEARCH" to what ever you want to search. Example, "Linux Commands"

Q="Hello world"; GOOG_URL="http://www.google.com/search?q="; AGENT="Mozilla/4.0"; stream=$(curl -A "$AGENT" -skLm 10 "${GOOG_URL}\"${Q/\ /+}\"" | grep -oP '\/url\?q=.+?&amp' | sed 's/\/url?q=//;s/&amp//'); echo -e "${stream//\%/\x}"
python -c 'import googl; print googl.Googl("<your_google_api_key>").shorten("'$someurl'")[u"id"]'
2012-05-31 17:14:17
User: shr386
Functions: python

(1) required: python-googl ( install by: pip install python-googl )

(2) get from google API console https://code.google.com/apis/console/

gg(){ lynx -dump http://www.google.com/search?q=$@ | sed '/[0-9]*\..http:\/\/www.google.com\/search?q=related:/!d;s/...[0-9]*\..http:\/\/www.google.com\/search?q=related://;s/&hl=//';}
2012-04-21 03:31:26
User: chon8a
Functions: sed
Tags: sed lynx google

Get the first 10 google results form a querry, but showing only the urls from the results.

Use + to search diferent terms, ex: commandlinefu+google .

say() { curl -sA Mozilla -d q=`python3 -c 'from urllib.parse import quote_plus; from sys import stdin; print(quote_plus(stdin.read()[:100]))' <<<"$@"` 'http://translate.google.com/translate_tts' | mpg123 -q -; }
(IFS=$'\n'; ln -sf $(awk '((NR % 2) != 0 && NR > 1) {print "prefix" $0}' list.m3u) target_folder)
2011-09-25 16:45:28
User: lxe
Functions: awk ln

This command will place symbolic links to files listed in an m3u playlist into a specified folder. Useful for uploading playlists to Google Music.

prefix = The full path prefix to file entries in your .m3u file, if the file paths are relative. For example, if you have "Music/folder/song.mp3" in your list.m3u, you might want to specify "/home/username" as your prefix.

list.m3u = Path to the playlist

target_folder = Path to the target folder in which you would like to create symlinks

p=$(echo "hello world, how r u?"|sed 's/ /+/g');wget -U Mozilla -q -O - "$@" translate.google.com/translate_tts?tl=en\&q=$p|mpg123 -
2011-09-19 23:06:15
User: jhansen
Functions: echo mpg123 sed wget

same but redirecting to player and putting whaever text line.. works on my ubuntu machine ...

say() { local IFS=+;mplayer "http://translate.google.com/translate_tts?q=$*"; }
say() { mplayer "http://translate.google.com/translate_tts?q=$1"; }
2011-09-08 03:34:24
User: daa

Usage examples:

say hello

say "hello world"

say hello+world

say() { wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?tl=en&q=$1"; gnome-terminal -x bash -c "totem output.mp3"; sleep 4; totem --quit;}
2011-09-07 19:48:53
User: totti
Functions: bash sleep wget

No need to install additional packages


say hello

For multiword

say how+are+you

curl pagerank.bz/yourdomain.com
google "search terms" #see description for more details
2011-07-04 09:37:39
User: husmanahmed
Functions: more

Inspired by: http://www.commandlinefu.com/commands/view/8744/search-google-on-os-x

#!/bin/bash if [ -n "$1" ] then firefox 'http://www.google.com/search?q="'$1'"' else firefox 'http://www.google.com' fi

Ive aliased this script as 'google' on my system and I can type 'google "search terms"' to open firefox with my search terms. My first post here, if there are any improvements to be made please let me know in the comments.

alias google='open http://www.google.com/search?q="'
2011-06-29 20:23:20
Functions: alias


google query_with_spaces "

so, make sure to end your query with a double quote

say(){ mplayer -user-agent Mozilla "http://translate.google.com/translate_tts?tl=en&q=$(echo $* | sed 's#\ #\+#g')" > /dev/null 2>&1 ; }
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te" | sed 's/dict_api\.callbacks.id100.//' | sed 's/,200,null)//'
2011-03-08 15:00:39
User: sairon
Functions: sed wget
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=steering+wheel&sl=en&tl=en&restrict=pr,de&client=te"

this does the actual google dictionary query, returns a JSON string encapsulated in some fancy tag

sed 's/dict_api\.callbacks.id100.//'

here we remove the tag beginning

sed 's/,200,null)//'

and here the tag end

There are also some special characters which could cause problems with some JSON parsers, so if you get some errors, this is probably the case (sed is your friend).

I laso like to trim the "webDefinitions" part, because it (sometimes) contains misleading information.

sed 's/\,\"webDefinitions.*//'

(but remember to append a "}" at the end, because the JSON string will be invalid)

The output also contains links to mp3 files with pronounciation.

As of now, this is only usable in the English language. If you choose other than English, you will only get webDefinitions (which are crap).

wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=hello+world
2011-03-08 14:05:36
User: sairon
Functions: wget

EDIT: command updated to support accented characters!

Works in any of 58 google supported languages (some sound like crap, english is the best IMO).

You get a mp3 file containing your query in spoken language. There is a limit of 100 characters for the "q" parameter, so be careful. The "tl" parameter contains target language.

wget -q -U "Mozilla/5.0" --post-file speech.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com/speech-api/v1/recognize?lang=en-us&client=chromium"
2011-03-08 13:39:01
User: sairon
Functions: wget

The FLAC audio must be encoded at 16000Hz sampling rate (SoX is your friend).

Outputs a short JSON string, the actual speech is in the hypotheses->utterance, the accuracy is stored in hypotheses->confidence (ranging from 0 to 1).

Google also accepts audio in some special speex format (audio/x-speex-with-header-byte), which is much smaller in comparison with losless FLAC, but I haven't been able to encode such a sample.

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)

rtfm() { help $@ || man $@ || open "http://www.google.com/search?q=$@"; }
2011-01-26 06:23:42
User: vaporub
Functions: man
Tags: man google

Simple edit to work for OSX.

Now just add this to your ~/.profile and `source ~/.profile`

rtfm() { help $@ || info $@ || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
2011-01-05 21:26:51
Functions: info man
Tags: man info google

Some commands have more information on 'info' than in the man pages

rtfm() { help $@ || $@ -h || $@ --help || man $@ || $BROWSER "http://www.google.com/search?q=$@"; }
2011-01-05 17:36:26
User: karol
Functions: man
Tags: man google

Sometimes you don't have man pages only '-h' or '--help'.