Google Search from Linux Terminal

33

22

I saw a Google console app someone wrote a while back, but it was actually a website emulating a console.

What I'm after is a shortcut or Linux terminal app which I can use to quickly search Google.

Ideally, it will show the top 10 search results with numbers next to them, and pressing the number will open the site in a browser.

Having the Google results open in a browser is fine too.

Does anyone have a solution?

Dean Rather

Posted 2009-09-26T14:03:33.987

Reputation: 2 499

Question was closed 2016-03-29T16:34:32.283

1Closed as off-topic? Can it not just be migrated? – neverMind9 – 2018-10-21T20:52:42.170

3

The website emulating a console - are you talking of goosh? http://goosh.org/

– None – 2009-09-26T14:36:15.883

3you will end up open the browser anyway, whats the point? – akira – 2009-09-26T15:53:11.893

6the point is to issue google searches from the terminal where we spend most of our time and are most comfortable. it might also be neat to have your recent google searches all visible in a command line history. – Landon Kuhn – 2012-11-05T06:37:19.203

Answers

11

google-cli is supposed to do just that (it's the revived version of cli-google).

Wernight

Posted 2009-09-26T14:03:33.987

Reputation: 571

26

Here's a simple bash function that lets you type

google foo bar

and which will then open your default browser to display the Google results page for those search terms:

google() {
    search=""
    echo "Googling: $@"
    for term in $@; do
        search="$search%20$term"
    done
    xdg-open "http://www.google.com/search?q=$search"
}

Simply paste that in your terminal to give it a try.

For Windows or Mac OS X, substitute the last line with one of the following (assuming you are using Cygwin or similar on Windows):

Windows

start "http://www.google.com/search?q=$search"

Mac OS X

open "http://www.google.com/search?q=$search"

innaM

Posted 2009-09-26T14:03:33.987

Reputation: 9 208

2i turned this into a shell script for mac by changing xdg-open to open, removing the function part and then adding script to bin. Thanks! – Daniel Jacobson – 2015-07-12T19:53:34.030

simply gold!!!! – Thomas8 – 2016-03-15T22:10:05.270

If you are using oh-my-zsh, try the web-search plugin --> https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/web-search

– Jeff7566 – 2019-03-15T06:35:08.900

10

#!/bin/bash

if [[ $(echo $*) ]]; then

    searchterm="$*"

else

    read -p "Enter your search term: " searchterm

fi

searchterm=$(echo $searchterm | sed -e 's/\ /+/g')

lynx -dump http://www.google.com/search?q=$searchterm | less

Copy and paste this script into ~/bin, name it "goose" or something (GOOgle SEarch). Chmod it +x

Usage is:

goose searchterm

Clearly, you have to have Lynx installed.

tonybaldwin

Posted 2009-09-26T14:03:33.987

Reputation: 101

9

If you want to search from the command line and jump to a user-definable browser for results, another solution is use surfraw.

   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, 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.

It's available pre-packaged in some Linux distributions (Debian, Ubuntu, unknown others), from source at debian.org, and the latest development code and releases are available from the official git repository (now living on GitLab).

Installation instructions from tarball or deb file are found on the Wiki.

Trivia note : Surfraw was originally written by Julian Assange. (Acronym/backronym for 'SURFRAW' is Shell Users' Revolutionary Front Rage Against the World Wide Web.)

To do a Google search from the command line:
sr google archibald tuttle

In addition to plain old Google, there are a lot of other built in search types.

To search for an RFC dealing with S/MIME:
sr rfc s/mime

Translate a word:
sr translate logiciel

Find torrents:
sr piratebay free music

(These keyword search types continue to be updated.)

More advanced usage :

     $ surfraw google -results=100 RMS, GNU, which is sinner, which is sin?
     $ sr wikipedia surfraw
     $ sr austlii -method=phrase dog like
     $ /usr/lib/surfraw/rhyme -method=perfect Julian

Surfraw is configurable. You can set it up with some defaults, either per-user in $HOME/.surfraw.conf or system-wide in /etc/surfraw.conf :

SURFRAW_graphical_browser="/usr/bin/links2 -g"
SURFRAW_text_browser="/usr/bin/elinks"
SURFRAW_graphical=yes

Here I've set it to use links2 and elinks, but you can use Firefox, Chrome, or any others you prefer.

(Nb. links2 -g is a strange terminal-embedded graphical-mode browser. It's fast but hates modernity.)

belacqua

Posted 2009-09-26T14:03:33.987

Reputation: 209

4

With wget, example:

wget -U 'Firefox/3.0.15' http://www.google.com/search?q=wget+google+query+to+file -O file.html

Source

Alexander

Posted 2009-09-26T14:03:33.987

Reputation: 41

1

I wrote a small application to allow you to do a Google search via CLI, it is actually very simple and currently only supports Web search, Images search and News search.

Codename: Gisele

$ php gisele.phar web -m 5 "stackoverflow"
1) Stack Overflow - http://stackoverflow.com/
2) Ask Question - http://stackoverflow.com/users/login
3) Stack overflow - Wikipedia, the free encyclopedia - http://en.wikipedia.org/wiki/Stack_overflow
4) Blog Stack Exchange - http://blog.stackexchange.com/
5) StackOverflow - IT Conversations - The Conversations Network - http://itc.conversationsnetwork.org/series/stackoverflow.html

Boris Guéry

Posted 2009-09-26T14:03:33.987

Reputation: 157

1

Lynx - a general purpose distributed information browser for the World Wide Web. Lynx is a fully-featured World Wide Web (WWW) client for users running cursor-addressable, character-cell display devices (e.g., vt100 terminals, vt100 emulators running on Windows 95/NT or Macintoshes, or any other "curses-oriented" display).

It will display hypertext markup language (HTML) documents containing links to files residing on the local system, as well as files residing on remote systems running Gopher, HTTP, FTP, WAIS, and NNTP servers. Current versions of Lynx run on Unix, VMS, Windows 95/NT, 386DOS and OS/2 EMX.

LinuxUser

Posted 2009-09-26T14:03:33.987

Reputation: 159

1

You can use w3m - a text based browser. You can open any website with it on terminal. In short you can have google in your terminal and search from there. If you are interested check this link.

To install w3m:

sudo apt-get install w3m

Rekha Nambrath

Posted 2009-09-26T14:03:33.987

Reputation: 11

1Please bring the relevant content of the link into the answer. – albal – 2015-08-14T09:53:10.467

1

the python guy is here now

#!/usr/bin/env python
import sys
import webbrowser

query = " ".join(sys.argv[1:]).encode('utf-8')
print('Query: "{}"'.format(query))
webbrowser.open_new_tab('http://www.google.com/search?q={}'.format(query))

Example usage:

$ google does this work?
query: "Does this work?"

Then it will open a web browser to this page

corvid

Posted 2009-09-26T14:03:33.987

Reputation: 111

0

If you're willing to sign up for a Google API key, you should be able to use the Net::Google Perl module in tandem with the Google SOAP API to do this. See here and here for simple perl scripts that use Net::Google.

You can also use the less specialised SOAP::Lite perl module for this task.

Alternatively, you can screen scrape Google queries via WWW::Mechanize, Web::Scraper or one of the many Perl screen-scraping modules, if you aren't disturbed by it's nebulous legal standing. Here's a good tutorial to get you started.

A command-line tool like this might work well when combined with a browser like Uzbl to provide a fast browsing experience.

user4358

Posted 2009-09-26T14:03:33.987

Reputation:

0

You can use a terminal browser like Elinks, which allows you to browse the web in the terminal and optionally open a link in another browser, like Firefox.

Richard Hoskins

Posted 2009-09-26T14:03:33.987

Reputation: 10 260

0

With Mac OSX I use an alias in my .bash_profil alias google=sh ~/scripts/google.sh

google.sh:

#!/bin/bash
open -g /Applications/Safari.app "http://www.google.com/search?q=$*"

Usage:

google word1 word2 ...

This way works fine for me.

cheers

Steven

Posted 2009-09-26T14:03:33.987

Reputation: 1

0

If you use KDE environment with default settings, ypu could search from krunner (called by Alt-F2 command).

For searching for query on Google, type in the krunner textbox:

gg:query

For searching for query on Wikipedia, type in the krunner textbox:

wp:query

Examples:

Alt-F2 + gg:Google search from terminal
Alt-F2 + wp:stackoverflow

Source: https://userbase.kde.org/Plasma/Krunner

gagallo7

Posted 2009-09-26T14:03:33.987

Reputation: 336

-1

Beagle can search from terminal. Or you've to look for browsers like Elinks.

Ryuken

Posted 2009-09-26T14:03:33.987

Reputation: 39

1Beagle link is not working !! – Suhaib – 2012-11-19T02:45:06.077