Terminal Tuts

How to search Wikipedia by command-line on Ubuntu

How to search Wikipedia by command-line on Ubuntu

Querying Wikipedia by command line via Ubuntu's Terminal is great fun. Today, I'm going to show you just that by using a free utility called wikipedia2text. This command-line utility queries the search term from the Wikipedia website and displays the result in the form of text within the Terminal.

You may want to know why one would search Wikipedia from Terminal? The reason can be as simple as you are operating a remote PC and would like to quickly search about a term in the world's biggest database. Wikipedia2text doesn't stop there. If needed, it can open the Wikipedia article in a GUI web browser or shows the URL of the relevant Wikipedia article.

Searching Wikipedia by command-line from Terminal

Before starting in the wikipedia2text installation, you need to make sure that you have a terminal-based web browser installed on your machine.

Step 1. In case you do not have a terminal-based web browser installed, then use the next command to install the Links web browser. Otherwise, skip this step if you have a terminal-based web browser installed.

sudo apt install links

Installing the Links Terminal Web Browser

Step 2. Now let's install the wikipedia2text package using the following command.

sudo apt-get install wikipedia2text

Installing wikipedia2text Package

Step 3. You can start querying Wikipedia after the installation is complete. You can use the wikipedia2text to help command to know the command usage of the utility. Enter the following command:

wikipedia2text -help

The wikipedia2text Help Command

Step 4. To show you an example of how to use query string, let's search Wikipedia for “Ubuntu,” use the next command.

wikipedia2text ubuntu

The previous command will search for the Ubuntu article in Wikipedia and will preview the result directly in your terminal, as you can see in the below screenshot.

Search For Ubuntu Articles In Wikipedia

Step 5. To preview results in a pager mode, use the next command.

wikipedia2text -p ubuntu

As you will notice, the pager mode will preview the result page by page; to move to the next page, press the space bar. If you need to quit the preview, press the “q” letter to exit.

Result For Ubuntu Articles In Wikipedia With The Pager Option

Step 6. To get results from Wikipedia in a different language, you can use the following command.

wikipedia2text -pl fr ubuntu

The above command will display the Ubuntu article from Wikipedia in the French language.

As you can see in the Ubuntu article is displayed in the French language.

Result For Ubuntu Articles In Wikipedia With The Pager Option In the French Language

Step 7. In case you need to get the Wikipedia URL for a specific article, uses the following command.

wikipedia2text -u ubuntu

Get The URL Of A Wikipedia Ubuntu Article

Congratulations, you have just learned how to search Wikipedia from your terminal.

Kuinka käyttää AutoKey-toimintoa Linux-pelien automatisointiin
AutoKey on työpöydän automaatioapuohjelma Linuxille ja X11: lle, ohjelmoitu Python 3, GTK ja Qt. Komentosarjojen ja MACRO-toimintojen avulla voit auto...
Kuinka näyttää FPS-laskuri Linux-peleissä
Linux-pelaaminen sai suuren työn, kun Valve ilmoitti Linux-tuesta Steam-asiakkaalle ja heidän peleilleen vuonna 2012. Siitä lähtien monet AAA- ja indi...
How to download and Play Sid Meier's Civilization VI on Linux
Introduction to the game Civilization 6 is a modern take on the classic concept introduced in the series of the Age of Empires games. The idea was fai...