1. Introduction
Sometimes, we delve into the intricate world of Linux commands, navigating through scripts, and encountering unfamiliar technical terms or commands. Hence, in these scenarios, having a dictionary accessible through the Linux command line becomes important.
In this tutorial, we’ll explore various command-line dictionaries in a Linux environment.
2. Using dict
dict is a command-line dictionary client in Linux to access word definitions, synonyms, and other word-related information from various dictionary sources available on the Internet. Importantly, access to dict servers is required for the application to work.
Let’s begin by installing the application via apt:
$ sudo apt-get install dict
Once installed, we use dict to find the definition or information by supplying a term as an argument to the dict command:
$ dict linux
3 definitions found
From WordNet (r) 3.0 (2006) [wn]:
Linux
n 1: an open-source version of the UNIX operating system
From The Jargon File (version 4.4.7, 29 Dec 2003) [jargon]:
Linux
/lee'nuhks/, /li?nuks/, not, /li:?nuhks/, n.
The free Unix workalike created by Linus Torvalds and friends starting
about 1991. The pronunciation /li'nuhks/ is preferred because the name
?Linus? has an /ee/ sound in Swedish (Linus's family is part of Finland's
6% ethnic-Swedish minority) and Linus considers English short /i/ to be
closer to /ee/ than English long /i:/. This may be the most remarkable
hacker project in history ? an entire clone of Unix for 386, 486 and
Pentium micros, distributed for free with sources over the net (ports to
Alpha and Sparc and many other machines are also in use).
...
From The Free On-line Dictionary of Computing (30 December 2018) [foldoc]:
Linux
<operating system> ("Linus Unix") /li'nuks/ (but see below)
An implementation of the {Unix} {kernel} originally written
from scratch with no proprietary code.
...
As we can see, we retrieved information from different sources, offering various definitions and descriptions of the term linux.
3. Using wn
The wn command in Linux is a powerful command-line interface that provides access to the WordNet lexical database. Hence, we can query and explore various aspects of words, including their definitions, synonyms, antonyms, and semantic relationships, all from the terminal or command line.
First, let’s install the wordnet package:
$ sudo apt-get install wordnet
Then, we use wn followed by options and a word to look up definitions, synonyms, antonyms, and more:
- wn word -over: overview of word
- wn word -syns: synonyms of word
- wn word -ants: antonyms of word
- wn word -hypen: hypernyms (more general concepts) of word
- wn word -hypon: hyponyms (more specific concepts) of word
To illustrate, let’s see an example of using wn to get information about a word:
$ wn happy -over
Overview of adj happy
The adj happy has 4 senses (first 2 from tagged texts)
1. (37) happy -- (enjoying or showing or marked by joy or pleasure; "a happy smile"; "spent many happy days on the beach"; "a happy marriage")
2. (2) felicitous, happy -- (marked by good fortune; "a felicitous life"; "a happy outcome")
3. glad, happy -- (eagerly disposed to act or to be of service; "glad to help")
4. happy, well-chosen -- (well expressed and to the point; "a happy turn of phrase"; "a few well-chosen words")
The output provides a comprehensive view of the various contexts in which the word happy can be used, showcasing different meanings and synonyms associated with it. Each sentence presents a distinct aspect or usage of the word, illustrating its versatility in the English language.
4. Using sdcv
sdcv is the console version of StarDict dictionary software. It’s a tool for Linux to access dictionary definitions and translations directly from the terminal.
To begin with, let’s install sdcv:
$ sudo apt-get install sdcv
Once it’s installed, we create a directory where sdcv should expect to find its dictionaries:
$ sudo mkdir -p /usr/share/stardict/dic/
Here, we used -p to create a directory and any necessary parent directories that don’t exist.
At this point, we download a dictionary file:
$ wget https://web.archive.org/web/20140428004049/http://abloz.com/huzheng/stardict-dic/misc/stardict-xfardic-gnu-linux-2.4.2.tar.bz2
Notably, we use the Web archive to get the file, because the original hosting has stopped working.
Then, we extract the contents of the dictionary into the directory we created:
$ sudo tar -xvjf stardict-xfardic-gnu-linux-2.4.2.tar.bz2 -C /usr/share/stardict/dic
Let’s break down the code:
- -x extracts files from an archive
- -v verbose mode displays detailed information about the extraction process
- -j indicates that the archive is compressed with bzip2
- -f specifies the archive file to be processed
- -C specifies the directory where the contents of the archive will be extracted
At this point, we search for words:
$ sdcv Linux
Found 1 items, similar to Linux.
-->GNU/Linux English-English Dictionary
-->Linux
UNIX-compatible operating system (and kernel) designed with free software tools and ported to several hardware architectures. Linux was initially developed by Linus Torvalds in 1991. Linux is open source software (OSS) and aims to be a viable alternative to competing proprietary operating systems. From Redhat-9-Glossary http://www.tldp.org/LDP/Linux-Dictionary/
In this case, we look up the definition or information related to the word Linux in the installed dictionaries.
5. Using Online APIs
Some command-line tools such as curl enable us to access online dictionary APIs and fetch definitions from services by leveraging web-based APIs.
Let’s see how we can send a manual DICT protocol request via curl directly to dict.org:
$ curl dict://dict.org/d:happy
220 dict.dict.org dictd 1.12.1/rf on Linux 4.19.0-10-amd64 <[email protected]>
250 ok
150 1 definitions retrieved
151 "Happy" gcide "The Collaborative International Dictionary of English v.0.48"
Happy \Hap"py\ (h[a^]p"p[y^]), a. [Compar. {Happier}
(-p[i^]*[~e]r); superl. {Happiest}.] [From {Hap} chance.]
1. Favored by hap, luck, or fortune; lucky; fortunate;
successful; prosperous; satisfying desire; as, a happy
...
2. Experiencing the effect of favorable fortune; having the
feeling arising from the consciousness of well-being or of
enjoyment; enjoying good of any kind, as peace,
...
3. Dexterous; ready; apt; felicitous.
[1913 Webster]
...
.
250 ok [d/m/c = 1/0/16; 0.000r 0.000u 0.000s]
221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s]
In this case, we retrieved information without relying on a specialized tool, Web browser, or graphical interface. Due to the ubiquity of curl, this can be useful when running an automatic script in an unknown environment.
6. Conclusion
In this article, we delved into the world of command-line dictionaries within the Linux environment.
Overall, these tools provide a versatile way to access word definitions, synonyms, antonyms, and other linguistic information directly from the terminal in Linux.