Home Terminal Tuts How to search Wikipedia by command-line on Ubuntu

How to search Wikipedia by command-line on Ubuntu

by Hend Adel
Published: Updated:
search wikipedia linux terminal

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
Install The Links Terminal Web Browser

Installing the Links Terminal Web Browser

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

sudo apt-get install wikipedia2text
Install The wikipedia2text Package

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

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

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

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 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

Get The URL Of A Wikipedia Ubuntu Article

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

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.