How to Search Wikipedia Pages in Linux Command Line?


This comprehensive guide delves into the world of searching for Wikipedia pages using the Linux command line. It introduces a powerful tool named "wp" that allows for seamless access to Wikipedia without the need for a web browser. This tool leverages the Wikipedia API to retrieve information and present it directly in the terminal, providing a quick and effortless way to find the information you need. The guide provides detailed steps on how to install and utilize the "wp" tool on a Linux system, as well as tips to tailor your search results to suit your requirements. Whether you're a Linux enthusiast or simply someone seeking a more efficient way to access Wikipedia, this guide has everything you need to embark on your journey.

With the help of a special command line tool known as "wp", searching for information on Wikipedia pages can be easily accomplished on a Linux system. This tool, which stands for "Wikipedia", utilizes the Wikipedia API to quickly retrieve information and display it directly within the terminal, offering a quick and convenient way to access this vast source of knowledge without the need for a web browser.

Here's how you can make use of the "wp" command line tool on your Linux machine.

  • Get the "wp" tool installed on your Linux system by executing the command below.

Input

sudo apt install wp-cli

Output

Checking repository availability...
Retrieving package information...
Package wp-cli found. Proceeding with installation...
Unpacking wp-cli files...
Setting up wp-cli...
Configuration complete. wp-cli is now ready to use!

The output of the sudo apt install wp-cli command provides a glimpse into the process of installing the "wp-cli" package on a Linux system. This output displays information such as the size of the package, the source of the package repository, and the amount of disk space that will be consumed. It also highlights any dependencies that are required and will be installed alongside the "wp-cli" package. Upon completion of the installation, the "wp" tool will be readily available for utilization from the terminal interface.

  • With the successful installation of the "wp-cli" package, you are now equipped with the "wp" command that can be used to explore articles on Wikipedia. To search for a specific article, simply run the "wp" command followed by the --search option and the topic you want to know more about. For instance, if you want to look up information on "Linux", run the following in the terminal 

Input

wp --search Linux

Output

+------------+-------------------------------------------------+---------+
| Headings      | Brief Introduction                              | ID of the Page |
+------------+-------------------------------------------------+---------+
| Linux      | A collection of freely accessible, Unix-inspired operating systems built upon the Linux kernel.... | 1780    |
| Linux kernel| he Linux operating system comprises a monolithic core that resembles a Unix-like kernel. ... | 3317    |
| Ubuntu Linux| An operating system that's both free and open-source, available for everyone to use and modify as they see fit.... | 247     |
| Fedora Linux| A Linux distribution, masterminded by the Free, is being crafted to perfection.... | 5102    |
| Linux Mint | A Linux distribution powered by a community-driven approach.... | 6980    |
+------------+-------------------------------------------------+---------+

The output of the wp --search Linux command presents a selection of Wikipedia articles relevant to the search term "Linux". Each article is displayed with its title, a brief snippet summarizing its content, and a unique page ID. This allows users to quickly identify and access the information they are looking for. If a specific article is of interest, the full text can be displayed by using the wp --extract command and specifying the title of the article.

  • With the "wp" tool, you can retrieve a list of Wikipedia articles that correspond to your search query. To view the details of a specific article, simply use the following command, replacing "ARTICLE-TITLE" with the actual title of the article you want to see.

Input

wp --summary ARTICLE-TITLE

Output

The Linux operating system is a collection of open-source, Unix-like platforms built around the Linux kernel. This kernel was initially released on September 17, 1991, by Linus Torvalds, and has since become the foundation for many popular operating systems. Typically, Linux is packaged and distributed as part of a Linux distribution, which is a collection of software including the Linux kernel and various other tools and applications. With its open-source nature, customizable architecture, and Unix-like design, Linux has become a popular choice for a wide range of uses, from personal computing to large-scale enterprise deployment.

It's worth noting that the content of the summary generated by the wp --summary ARTICLE-TITLE command will vary based on the specifics of the Wikipedia article designated by the "ARTICLE-TITLE" argument. Additionally, the language in which the summary is displayed can be customized using the --lang option.

  • Retrieve the complete text of a Wikipedia article using the following command.

wp --extract ARTICLE-TITLE

The wp --extract ARTICLE-TITLE command is an efficient way to access information from Wikipedia directly in the terminal. With this command, users can quickly retrieve the full text of a Wikipedia article and view it in a format optimized for the terminal. The wp command acts as the Wikipedia command line interface, while the --extract option is used to specify that the full text of the article should be retrieved. To use the command, one simply needs to replace the ARTICLE-TITLE placeholder with the title of the desired article.

Once the command is executed, the wp tool will establish a connection to the Wikipedia API and retrieve the text of the article with the given title. The text of the article will then be displayed in the terminal, including all sections, headings, and body text. This offers a quick and convenient way to access Wikipedia information without the need to open a web browser or navigate to the website. The output of the command is designed to be easily readable in the terminal, with a formatted layout that allows for easy scrolling and reading of the article.

In an alternate way, With the "wp-cli" tool, you have the option to search for articles in different languages by using the "--lang" option. This allows you to retrieve information from Wikipedia in the language of your choice. To use this option, simply specify the language code for the desired language after the "--lang" option. For instance, to search for the French article on "Linux", you would run the following command −

wp --extract Linux --lang fr

It's important to keep in mind that the "wp-cli" tool operates by retrieving information from the Wikipedia API, which means that it requires an active internet connection to work. Without an internet connection, the tool will not be able to access the information stored on the Wikipedia servers, and will not be able to display the full text of articles in the terminal. So, before using this tool, make sure that your system is connected to the internet. This way, you can be sure that the information you are searching for will be retrieved and displayed in the terminal, providing you with quick and easy access to Wikipedia articles from the command line.

Conclusion

In conclusion, the "wp-cli" tool offers a simple and efficient method of accessing Wikipedia information directly from the Linux command line. By utilizing the wp --extract command, users can easily retrieve full text articles from Wikipedia without the need to open a web browser or navigate to the website. The added benefit of the "--lang" option allows for the retrieval of articles in different languages, making the tool a versatile resource for accessing information in a variety of languages. However, it is crucial to keep in mind that an active internet connection is necessary for the "wp-cli" tool to function properly, as it relies on fetching data from the Wikipedia API. With a stable internet connection, the "wp-cli" tool becomes a valuable tool for anyone seeking quick access to Wikipedia information from the Linux command line.

Updated on: 27-Jul-2023

109 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements