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
Step 2. Now let’s install the wikipedia2text package using the following command.
sudo apt-get install wikipedia2text
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:
Step 4. To show you an example of how to use query string, let’s search Wikipedia for “Ubuntu,” use the next command.
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.
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.
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.
Step 7. In case you need to get the Wikipedia URL for a specific article, uses the following command.
wikipedia2text -u ubuntu
Congratulations, you have just learned how to search Wikipedia from your terminal.