cli-google: google search from terminal

Who wants to leave the comfort of the terminal and open a browser to search Google? 😉 We explored several ways to search google in our earlier articles (GoogleCL, Surfraw). How about some cool utilities that do not need much setup or learning? I revived one myself.

During my search I found the following script on commandlinefu:

function google { Q="$@"; GOOG_URL=''; 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}"; }

It works well in bash but shows only the URLs. Normally the URLs don’t make a lot of sense after the top 10 results.

I came across cli-google, exactly the thing that I was looking for. It was written to show the result title with URL and brief text snippet. If you use a URL-aware terminal like AltYo, you can click and open the links in your default browser. However, it turned out this python utility doesn’t work anymore. I am not a python programmer but I started modifying this promising utility and it’s in a presentable state now.


  • Fetch first n results
  • Fetch results starting at result n
  • Support for different languages
  • Coloured output
  • Open first result in the web browser (remember I’m Feeling Lucky?)

My fixes and modifications

  • Use https
  • Handle google redirections (error 302)
  • Show full text context snippet of search results
  • Unicode in URL works
  • Time limit search
  • Support filetype specific search
  • Colour output by default, -C now disables it (toggled)
  • The first URL now correctly opens in browser with -j switch
  • Honour -j even if -n is not used and open the result in browser
  • Fixed character encoding problem in URL e.g. double quotes (%22) changed to %2522
  • Skip browser to show result in console for empty URL, e.g., first result of ‘define hello’


  • Support country specific Google server
  • Anything else you can think of


Initially I raised a pull request but I could see that the last change was made 7 years earlier. In addition, there is no GitHub activity from the author in past year. I have created an independent repo for the project with the name google-cli. Would love to push the changes back to original repo if the author contacts. I retained the original copyright information.


Run the following command to fetch the repository:

$ git clone


The following options are supported:

  -s N     start at the Nth result
  -n N     shows N results
  -l LANG  display in language LANG, such as fi for Finnish
  -C       disable color output
  -j       open the first result in a web browser
  -f MIME  search for specific file type
  -t dN    time limit search [e.g. d5: 5 days, w5: 5 weeks, m5: 5 months, y5: 5 years]

Contributions are welcome!

On GitHub: google-cli

Leave a Reply

Your email address will not be published. Required fields are marked *