Command-line search engine

Googler

© Lead Image © Andrea Danti, fotolia.com

© Lead Image © Andrea Danti, fotolia.com

Article from Issue 202/2017
Author(s):

With a few customizations, Googler plus a text-based browser offers faster, more accurate searching than a traditional web browser.

These days, doing a web search from the command line may seem like an anachronism. However, Googler [1] can be useful in a number of ways. It provides a headless search engine that can be called within a script. When combined with a text-based browser, it gives you access to the Internet. Most important of all, Googler offers the same search options and presentation of results as the Google home page, but with the use of a few aliases, in fewer keystrokes.

Googler is available in many distributions and runs in the most common command shells. However, you can get the latest stable version by running the command googler -u as soon as you install. To obtain the latest, possibly unstable, version, you can add --include-git to the command as well. Alternatively, if the latest version seems more of a risk than you are willing to take, you can compile Googler yourself with the command:

make disable-self-upgrade

Additionally, if you plan on using Googler with a text-based browser, such as ELinks, Links, Lynx, or w3m, set the Browser environment variable with:

export BROWSER=[BROWSER]

To use a text-based browser temporarily, enter:

BROWSER=[BROWSER] googler query

Options

Googler uses the standard command structure COMMAND OPTIONS STRING. As in Google itself, the search string should be enclosed in double quotation marks (") when you want to search for an exact phrase. The majority of options are divided into two categories: search filters and customization of search results.

Search filters are similar to those available on the Google home page. The difference is that, while many search filters are available on Google only after you make the initial search, you can add search filters directly into the googler command and combine them more easily. Even if you are using googler without shortcuts (see below), the number of characters entered with googler is about equal to the number of clicks required on the Google home page, which means that a Googler search is somewhat faster once you have memorized the search filters.

As you filter a search, you probably want to begin with

--count=NUMBER (-n)

to set the number of results per page. (The entry in the parentheses is the short form of the option.) If you are previously familiar with the results, or you hope to sidestep Google's placement of personalized results at the top of the first page, you can specify the first result to display:

start=NUMBER (-s)

Using --count and --start together displays results starting with the one specified by --start. Other search filters include

tld=TOP LEVEL DOMAIN (-c)

to search in a specific version of Google – for example, google.ca for Canada rather than google.com. A two-character abbreviation is used for each country [2]. Similarly

--lang=LANGUAGE (-l)

returns only results in the language and locale specified using a two-character abbreviation for the language, separated from the two-character locale code – for example, en-uk is the English language as spoken in the United Kingdom [3]. In the same way,

--times= UNIT NUMBER (-t)

specifies how long ago the results were posted, with options for the units h (hours), d (days), w (weeks), m (months), and y (years); therefore, -t=w3 would look for results posted in the last three weeks.

Search filters can also be used to specify a site. The option

--news (-N)

specifically searches Google News, and

site=URL (-S)

searches only the defined site. You can also enter

--first (--lucky, -j)

to limit output to the first result found – the equivalent of the Google I'm Feeling Lucky button.

Another set of options specifies the colors used to display results (Figure 1). By default, six characters are used to define colors. In order, they represent the indices, titles, URLs, metadata (for searches in Google News), abstracts, and prompts. Each can be assigned a basic, bright, or bold color option (Table 1) using the option:

--colors= SIX LETTER STRING (-c)
Figure 1: The first two color-coded results of a search for the Gentium font.

Table 1

Color Options

a

Black

b

Red

c

Green

d

Yellow

e

Blue

f

Magenta

g

Cyan

h

White

I-P

Bright versions of the regular colors above

A-H

Bold versions of the regular colors

y

Reverse normal colors

Y

Reverse bold colors

To use a set of colors permanently, set the environment variable GOOGLER_COLORS. These codes are entered with:

--colors= SIX LETTER STRING (-c)

Normal colors (y) and bold colors (Y) can also reverse foreground and background. If you prefer to have no colors, use:

--nocolor (C)

Navigating Results

When results display, you can open a result in your default web browser by entering its number at the bottom of the list. Keyboard shortcuts – which Googler help refers to as "omniprompt keys" – are available to help you navigate through the list (Table 2). Selections open in the web browser, but you must return to the results to navigate.

Table 2

Googler Omniprompts

n

Next search result

p

Previous search result

index

Return to complete list of search results

f

Jump to the first page of results, if any

o [INDEX|RANGE|a]

Move to indices, a range of results, or all results

g [KEYWORDS]

Do a search for keywords within obtained results

q, ^D, double Enter

Exit Googler

?

Show omniprompt help

*

Start a new search using the original options

Shortcuts

Unlike most applications, Googler does not have a configuration file. However, you can store preferences for items, such as text-based browsers and color schemes, to save typing.

Also, Googler has several ways of storing searches. None of these choices are necessary, but you might explore them to see which suits you.

To start, Googler has autocompletion files for bash [4], fish [5], and zsh [6]. Another option that is installed with Googler is the googler @t add-on, which includes the googler_at [7] configuration file of aliases.

googler_at contains hundreds of abbreviated aliases (Figure 2), ranging from social media sites like Facebook and the Linux Kernel Mailing List to resources such as the Debian package search page and the Ubuntu man pages. To use googler_at, enable it by entering the command:

source googler_at
Figure 2: googler_at comes with a file of ready-to-use aliases, to which you can also add your own.

Although the message displays that the file cannot be found, you can then use the file's aliases. For example, entering

@w debian

searches Wikipedia for references to Debian. You can add aliases using the standard alias command. For example, the command:

alias m='googler -n 20 -c en -l us'

returns results in pages of 20 in US English. These aliases require some memorization, but, for ones you use regularly, they can greatly increase Googler's speed. Just be sure that none of Googler's aliases conflict with ones that you have already made.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Clever Tracker

    If you are a genuine admin, you will want to be able to google things at the command line. Charly uses googler for this; it has pretty useful capabilities despite the unimaginative name.

  • FOSSPicks

    Sparkling gems and new releases from the world of Free and Open Source Software.

  • ddgr Search

    Since 2008, DuckDuckGo has been making waves as an efficient and much more private search engine alternative to Google. The unaffiliated command-line tool ddgr is designed to make running DuckDuckGo searches from the terminal a breeze.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News