When you want to do a search in Google, the most common behavior is to open a browser, load the Google website and type in your search term. For those command line geeks, how about an easier way to run Google search from the command line?
Run Google search from the command line
To access Google using the command line in Linux you need to download and install a tool called Googler. Aside from searching the web, the tool also lets you access Google News and perform Google Site Search from the command line.
Downloading and installing Googler is very easy. All you have to do is to run the following command:
sudo curl -o /usr/local/bin/googler https://raw.githubusercontent.com/jarun/googler/v2.9/googler && sudo chmod +x /usr/local/bin/googler
Once the above command is executed, you can easily launch the utility by running the following command:
Note: of course, there are other ways of downloading/installing the tool, like from source. All the related details can be accessed by heading to the project’s GitHub page.
Moving on, when you run the
googler command, the tool will ask you to enter a query.
For example, I entered the word “Maketecheasier” as the query text.
After I pressed enter, here’s the output produced by the utility.
You can see that the Google search results for the query were displayed right on the terminal screen itself. You’ll also notice that each search result is indexed (I am talking about those blue colored numbers: 1, 1a, 1b, etc.). These indexes are used when you want to open a particular result.
For example, to open the first result, you just have to type “1” and press Enter.
If you are running a GUI-based Linux distro (which you most likely are), the above operation will result in Googler triggering your default web browser (in my case it was Chrome) and opening the first search result in the browser.
Admittedly the fact that you have access to a GUI-based web browser and are still performing Google searches on the command line (only to open the results in the browser again) doesn’t make much sense. So, here’s how you can configure Googler to launch a command-line based browser.
For one-time use, run the following command:
And to permanently set the change, run the following command:
Then use Googler normally.
For the uninitiated, “lynx” (used in the previous example) is a popular command line browser. To install it, you can run the following command:
sudo apt-get install lynx
For more run-time options that Googler provides, type “?” and press Enter.
Aside from run-time options, Googler also provides many command line options. The following screenshot (taken from the tool’s GitHub page) lists them all:
Knowledge of all these options will enable you to perform some complicated search operations. For example, to fetch fifteen results updated within the last fourteen months, starting from the third result for the string “himanshu” in website “maketecheasier.com,” run the following command:
googler -n 15 -s 3 -t m14 -w maketecheasier.com himanshu
Here’s the list of Googler features that the developer advertises:
- Google Search, Google Site Search, Google News
- Fast and clean (no ads, stray URLs or clutter), custom color
- Navigate result pages from omniprompt, open URLs in browser
- Fetch n results in a go, start at the nth result
- Disable automatic spelling correction and search exact keywords
- Specify duration, country/domain (default: worldwide/.com), language
- Google keywords (e.g. filetype:mime, site:somesite.com) support
- Open the first result directly in browser (as in I’m Feeling Lucky)
- Non-stop searches: fire new searches at omniprompt without exiting
- HTTPS proxy, User Agent, TLS 1.2 (default) support
- Man page with examples, completion scripts for Bash, Zsh and Fish
- Minimal dependencies
For more details on the tool, head here.
Googler is undoubtedly a good solution for your command line Google search problems. The fact that it provides a plethora of features and its GitHub page contains extensive documentation makes the tool all the more enticing. Give it a try, and I am sure you won’t be disappointed.