Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Search Google from the command line UNIX
Often I'm working at the command line, and want to do a quick Google search on a topic. So I wrote a tiny shell script to make this easy, saving several clicks!

To use the script, simply type google your search terms while you're in Terminal. For example, typing google mac os x turns up pages about our favorite OS (this site is #3!). If you're on your local machine, the search results open in your favorite browser. If you're logged in via SSH, the search results open in the links command-line browser, which you can download here.

You can download the script from me, or copy and paste the following:
for this_query_term in $@

remote_addr=`who am i | awk -F\( '{print $2}' | sed 's/)//'`

if [ -z "$remote_addr" ]; then
open "$url"
links "$url"
Just copy-and-paste the script into a text file (call it 'google' to match the examples listed here), and make it executable (chmod 755 google). You'll want to place it somewhere that is in your path, such as /usr/bin, or better, put it in ~/bin and add that to your path.
  • Currently 2.67 / 5
  You rated: 5 / 5 (6 votes cast)

Search Google from the command line | 9 comments | Create New Account
Click here to return to the 'Search Google from the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Requries OS X 10.2 ?
Authored by: leejoramo on Oct 09, '02 10:50:51AM
I am not getting this to work on my Mac OS X 10.1.5 system. The following error occurs:

2002-10-09 08:42:27.375 open[476] No such file: /Users/ljoramo/bin/http:/

I suspect that the version of the open command on my system does not support passing URL's, this feature was probably added in Jaguar. I did a quick search but could not confirm this. The new hard drive, AirPort card and Jaguar are sitting on my desk waiting to upgrade my Titanium. Maybe tonight...

Lee Joramo

[ Reply to This | # ]
or make an alias
Authored by: pink on Oct 09, '02 11:53:19AM

you can also make an alias that does the same:

alias google 'open\?q=\!*'

(there is supposed to be a backslash each before the ? and the !
somehow this is edited out....)
just have to remember to use the right nomenclature, e.g.
google me+you+all

cheers, pink

[ Reply to This | # ]
Or install surfraw....
Authored by: sao on Oct 09, '02 04:09:28PM

I installed surfraw-1.0.7-1 with Fink to satisfy all my google and other searching needs from terminal.

"Surfraw provides a fast unix command line interface to a variety of popular WWW search engines and other artifacts of power. It reclaims google, altavista, babelfish, dejanews, freshmeat, research index, slashdot and many others from the false-prophet, pox-infested heathen lands of html-forms, placing these wonders where they belong, deep in unix heartland, as god loving extensions to the shell."

202 Sao @ ~ $ surfraw
W----------------------------- Activate Surfraw defined web-browser
altavista-------------------- Search the web using Altavista (
amazon-------------------- Search the bookstore
appwatch----------------- Search entries on Appwatch (
ask------------------------- Question the web using Ask Jeeves (
austlii---------------------- Search Australian Law docs (
britannica----------------- Look up word in Encyclopedia Britannica (
cite ------------------------- Search computer science papers (
cnn-------------------------- Search on CNN (
currency ------------------ Abuse the Universal Currency Converter (
debbugs------------------ Search the debian BTS (
debcontents------------- Search contents of debian packages(
debpackages----------- Search debian packages (
deja------------------------ Search usenet using Deja News (
excite---------------------- Search on Excite (
fast------------------------- Search the web using FAST Search (
filesearching ----------- Search files on filesearching (
freebsd------------------- Search FreeBSD related information (
freshmeat--------------- Search Freshmeat (
ftpfind--------------------- Search files on ftpfind (
ftpsearch---------------- Search files on ftpsearch (
google------------------- Search the web using Google (
jake----------------------- Search journal/databases in jake (
netbsd------------------- Search NetBSD related information (
openbsd----------------- Search OpenBSD related information (
pubmed ----------------- Search medical/molbio databases (
raging-------------------- Search the web using Raging (
rhyme-------------------- Search for rhymes et al using Lycos Rhyme (
scaleplus--------------- Search Australian Law using ScalePlus (
slashdot---------------- Search stories on Slashdot (
slinuxdoc--------------- Search entries in LDP (
sourceforge----------- Search SourceForge (
stockquote------------- Get a single stock quote (multiple providers)
sundocs---------------- Search docs on (
sunsolve--------------- Search public docs on Sunsolve (
swhois------------------ Search Whois (
thesaurus-------------- Look up word in Merriam-Webster's Thesaurus (
translate---------------- Translate human languages (various providers)
webster----------------- Look up word in Merriam-Webster's Dictionary (
wetandwild------------ Real time weather information (many sources)
woffle------------------- Search the web using Woffle (localhost:8080)
xxx----------------------- Superior XXX, hot and ready to press (
yahoo------------------- Search Yahoo categories (

I use surfraw in combination with 'launch' (a replacement for "open" also installed with Fink) in order to open the urls in mozilla besides links or w3m and created aliases like the following:

alias go 'google -browser='launch''
alias bri 'britannica -browser='launch''
alias wet 'wetandwild singapore -browser='launch''


[ Reply to This | # ]
Or install surfraw....
Authored by: imacusr on Oct 09, '02 08:41:58PM

OMG, that is too cool. Downloading now....

[ Reply to This | # ]
the lizzard alternative
Authored by: metiure on Oct 09, '02 04:11:18PM

I don\'t know about the terminal. Looks like a great hint. But with real browsers, like
Mozilla, no script is needed at all, and you can search Google directly from the URL line.

Just add:


to your user.js prefs file.

Type your search, and Mozilla kindly takes you to Google, with plenty of great answers waiting for you!

[ Reply to This | # ]
the lizzard alternative
Authored by: DavidRavenMoon on Oct 09, '02 07:34:40PM

You don't even have to add that. It's already built in. Just set Google as the default search engine (Prefs/Navigator/Internet Search), then type your query in the address field and press the down arrow to highlight "Search Google for "(your text string)"" and hit Enter!

[ Reply to This | # ]
Authored by: rocteur on Oct 12, '02 12:39:37PM

This is really GREAT.. Thanks!!!

[ Reply to This | # ]
google in perl
Authored by: svanstrom on Oct 13, '02 08:35:46AM
Well... being a fan of perl I could of course not use that version, so I wrote my own. =)
I didn't compare the two, but I think his version couldn't handle situations where you wanted to use a search "word" containing a space; but mine does.
There shouldn't be any bugs, but if there are, or you've got a requrest for a feature, let me know at
Here's the link: google in perl.

[ Reply to This | # ]
surfraw patch
Authored by: flipflop on Sep 04, '04 03:27:16PM

If you want to use surfraw with your default browser, and don't want to set up all those aliases, all you need to do is:

(a) change one line in the surfraw script (if installed w/ fink, it is at /sw/bin/surfraw):

the line which reads:

if ok SURFRAW_graphical && test -n "$DISPLAY"; then

should be changed to read:

if ok SURFRAW_graphical; then

(it was written on the assumption that you would only want to use a graphical browser if X11 was running.)

(b) edit the surfraw.conf file (if installed w/ fink, it is /sw/etc/surfraw.conf):

You want to change:

def SURFRAW_graphical_browser mozilla


def SURFRAW_graphical_browser open

or (if you have launch installed):

def SURFRAW_graphical_browser launch

Now you should be able to run surfraw directly, without having to pass the browser option on the command line.

[ Reply to This | # ]