Whether or not you’re a confirmed command line-dweller, or simply terminal-curious, you’ve possibly puzzled how straightforward it’s to go looking the online with a easy textual content command. Effectively, Linux being Linux, there are a number of choices at your disposal.
The Most Acquainted Means: Google in a Browser
Let’s face it, Google has been so dominant for the previous 25 years that the search engine’s title has grow to be a verb which means “to go looking the web.” Chances are high, you utilize Google in a graphical net browser immediately, and any different should ship in the identical means.
Due to this fact, looking Google in a browser, from the command line as an alternative of a GUI, will most likely be your default beginning place. You might already use a text-based browser like Lynx; if not, you’ll want to organize for an adjustment interval. Viewing a text-only model of an internet site will expose all its flaws, from lacking alt-text to an over-dependency on JavaScript.
Having stated that, Google’s search interface is thought for its minimalism and this helps so much when viewing it in a textual content browser:
It’s fairly straightforward to navigate to the search field, enter your search, and see the outcomes. You may even go to the outcomes web page instantly, in the event you can keep in mind the URL and parameter:
$ lynx http://www.google.com/search?q=search+from+commandline
Exploring these outcomes, although, isn’t fairly as good an expertise:
You might choose to make use of a distinct service. DuckDuckGo is a privacy-focused search engine that makes use of an unlimited variety of sources, together with Bing, for its outcomes. With a textual content browser, it has an much more minimal interface than Google’s:
And DuckDuckGo’s search outcomes are a lot simpler to learn than Google’s, regardless of nonetheless being text-only. They’re clearly numbered and separated by white house:
The opposite vital possibility is Bing, however I’ve discovered Microsoft’s search engine troublesome to make use of with a textual content browser. Actually, if you actually need to make use of Bing, I like to recommend simply going to its outcomes straight relatively than attempting to make use of its search kind:
$ lynx "https://www.bing.com/search?q=search+from+commandline"
A Terminal Entrance-Finish to DuckDuckGo: ddgr
If you happen to’re proud of DuckDuckGo’s service, then there’s extra excellent news within the type of a terminal shopper. ddgr is a command-line tool, written in Python, that searches DuckDuckGo. It presents search leads to your terminal, every with a transparent title, description, and area or URL.
By default, ddgr operates in an interactive mode which offers the simplest means of opening a selected end result. Begin by coming into a search on the command line:
ddgr linux
ddgr will show a web page of outcomes, ten of them by default:
On the backside, ddgr presents a command line that you need to use interactively to refine outcomes or take additional motion. Enter the variety of the end result you need to view. If you happen to’ve configured a terminal browser, utilizing the widely-supported BROWSER setting variable, it’ll open and present the end result you selected. You can even have outcomes open in your graphical browser in the event you choose.
Restricted Search Outcomes With the DuckDuckGo API
At first look, DuckDuckGo’s API appears promising, and it’s very straightforward to make use of. For instance, you may get an inventory of Instantaneous Reply leads to JSON format utilizing this endpoint:
https://api.duckduckgo.com/?q=&format=json
With curl and a tool like jq to parse JSON, you may get near fetching helpful leads to a format that can be utilized for scripting and additional processing:
$ curl -s 'https://api.duckduckgo.com/?q=linux&format=json' |
jq -r '.AbstractURL'
Nevertheless, these outcomes are very restricted due to how DuckDuckGo licenses its syndicated outcomes. It’s price experimenting with search phrases within the context of your individual necessities, however be sure you notice that this method is not going to produce the identical outcomes as a search on duckduckgo.com.
A Complete Third-Occasion Search API—at a Value
SerpApi is an unofficial alternative to DuckDuckGo’s personal API. The distinction is that it could actually work throughout a number of search engines like google and offers full-text search outcomes. The downside is you’ll have to pay or take care of the 100-search month-to-month restrict on the free plan. If you happen to can settle for these limitations, SerpApi is an effective selection for scripted search outcomes:
$ curl -s 'https://serpapi.com/search?engine=duckduckgo&q=&api_key=' |
jq '.organic_results[0]'
Though HTTPS helps to stop sure varieties of knowledge leaks, typing your API key on the command line is a safety threat. To mitigate that, investigate curl’s options, specifically -Okay, -G, and -d.
Working this command gives you an object representing the primary search end result from DuckDuckGo:
The full API has many choices and helps a number of search suppliers, with an comprehensible deal with Google. However pricing is pricey—$75/month for as much as 5,000 searches—so it’s extra applicable for skilled work.
Every of those command-line web-searching strategies has a studying curve and comes with its personal advantages and downsides. This provides quite a lot of choices, so that you’ll need to have a great understanding of what you need to obtain earlier than deciding on one. Personally, I feel that ddgr presents the perfect compromise between usability and performance.