Friday, October 14, 2022
HomeNetworkingUtilizing Wikipedia from the Linux command line

Utilizing Wikipedia from the Linux command line


If you’re sitting in entrance of a Linux system, you’ll be able to all the time pop open a browser and question subjects of curiosity on Wikipedia. Alternatively, when you’re logged on via a terminal emulator like PuTTY otherwise you simply favor utilizing the command line, there may be another choice: wikit.

Wikit is a instrument that queries Wikipedia from the command line and offers summaries of its content material on an enormous assortment of subjects. It is easy to make use of and permits you to shortly question and, if you’d like, save the rendered info in a file.

The right way to use wikit

One of many issues Wikipedia won’t, at the very least presently, inform you about is wikit itself. So, this publish will present info on the command and present you ways you need to use it.

For instance, if I need to lookup one of many many cities the place I lived whereas rising up, I would run a command like this:

$ wikit Rahway
Rahway is a metropolis in southern Union County, New Jersey, United States. A bed room
 group of New York Metropolis, it's centrally positioned within the Rahway Valley area,
 within the New York metropolitan space. The town is 21.6 miles southwest of Manhattan
 and 5 miles west of Staten Island. Constructed on the navigable Rahway River, it was
 an industrial and artisanal craft metropolis for a lot of its historical past. The town has
 more and more reinvented itself lately as a various regional hub for
 the humanities. As of the 2010 United States Census, the town's inhabitants was 27,346,
 reflecting a rise of 846 (+3.2%) from the 26,500 counted within the 2000 Census,
 which had in flip elevated by 1,175 (+4.6%) from the 25,325 counted within the
 1990 Census.

I may simply save the returned textual content in a file like this:

$ wikit Rahway > Rahway

Wikit, which rhymes with phrases like “click on it” or “ticket”, retrieves the summaries from Wikipedia and, when you present an argument which matches a number of Wikipedia pages, will present an inventory of associated subjects which you could scroll via along with your up and down arrow keys. If I ask about 911, for instance, the checklist will begin with entries like these, however run on for fairly quite a lot of screens of extra subjects:

$ wikit 911
? Ambiguous outcomes, "911" could seek advice from: (Use arrow keys)
â–Ż AD 911
  911 BC
  September 11
  September 11 assaults
  11 de Septiembre
  November 9
  911 (quantity)
  9-1-1
  9-1-1 (Philippines)
  9/11: The Twin Towers
  9/11 (2002 movie)
  9/11 (2017 movie)
  Reno 911!: Miami
  Reno 911!
  Sep 11 (Noam Chomsky)

The right way to get wikit

Whereas wikit isn’t put in on Linux techniques by default, it solely takes a couple of steps to get it. You first want each nodejs and npm put in. In any other case, you’ll be able to set up them with a command like one in every of these:

$ sudo dnf set up nodejs npm
$ sudo apt set up nodejs npm

Then, to get wikit put in, use an npm command like this:

$ sudo npm set up wikit -g

I additionally ran the next command to improve to the most recent launch of npm after being prompted to take action.

 $ sudo npm set up -g npm@8.19.2

Getting and utilizing textual content from Wikipedia

If you happen to question a posh topic, be ready for wikit to supply one very lengthy line of textual content. For instance, if I ask Wikipedia for info on astronomy, I’d see this despite the fact that the file would comprise about 2,000 characters:

$ wikit astronomy > Astro
$ wc -l Astro
1 Astro

To separate all these characters into a number of strains with a most size of 80, however solely on phrase boundaries, I used this command:

$ fold -s -w80 Astro > Astro2
$ wc -l Astro2
24 Astro2

The -w80 specifies the utmost size of 80 whereas the -s tells it to interrupt on areas.

The place the unique file had a single line, the folded one has 24:

$ wc -l Astro
1 Astro
$ wc -l Astro2
24 Astro2

A multi-word topic doesn’t should be enclosed in quotes for wikit as this instance illustrates:

$ wikit pecan pie
 Pecan pie is a pie of pecan nuts blended with a filling of eggs, butter, and sugar
 (usually corn syrup). Variations could embrace white or brown sugar, cane syrup,
 sugar syrup, molasses, maple syrup, or honey. It's popularly served at vacation
 meals in the USA and is taken into account a specialty of Southern U.S. origin.
 Most pecan pie recipes embrace salt and vanilla as flavorings. Chocolate and
 bourbon whiskey are different fashionable additions to the recipe. Pecan pie is usually
 served with whipped cream, vanilla ice cream, or exhausting sauce.

After all, even Wikipedia isn’t going to offer you every part you’d prefer to know.

$ wikit pecan pie recipe
pecan pie recipe not discovered :^(

The language that wikit will use is specified within the wikit.jspn file and may be modified when you favor to see the topic summaries out there in different languages.

$ cat .config/configstore/wikit.json
{
        "lang": "en"
}$

Change “en” to “fr” and the outline of my outdated house city will appear like this:

$ wikit Rahway
 La ville de Rahway (en anglais ) est située dans le comté d’Union, dans l’État
 du New Jersey, aux États-Unis. Sa inhabitants s’élevait à 27346 habitants lors
 du recensement de 2010, estimée à 30131 habitants en 2017. Rahway fait partie
 du Grand New York.

Wrap-Up

Wikit offers a straightforward option to seize textual content from Wikipedia on the command line and to view it or retailer it in your Linux system.

Copyright © 2022 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments