Shell tool examples in the terminal
eg Explains
Need to know how to use a command-line tool? eg provides real life examples, and it is easier to access than the man pages.
On forums and in discussion groups, you increasingly find people claiming that using the command line is an anachronism. They say that it should be possible to handle any task with graphical tools. This kind of statement shows that whoever posted the comments has never seriously tried to work with a terminal. Anyone who is aware of the speed and elegance of working at the command line would never agree that graphical tools alone would be preferable. I admit to using a hybrid of command line and graphical tools on the Plasma desktop. I have increasingly used both, equally, in combination for many years, and there is no way I would want to do without the command line given this very satisfying division of labor.
Complex Man Pages
There are several ways to approach working in a terminal as a newcomer with the willingness to learn. The first place to start for many users is the man pages, which are great as a reference because they list all the options, flags, and parameters for a tool. But if you actually want to learn how to use command-line interface (CLI) tools, the man pages offer very limited help – in fact, they are more likely to scare off most newcomers. Hands-on examples provide far more easily digestible information, and there are countless examples on the web. The trick is finding the right example from such a massive selection.
This is where the interactive tool eg
enters the scene. It stands for exempli gratia (e.g. for short), which comes from Latin. The name makes sense, until you need to search the web or your hard drive for "eg" and are bombarded with matches. eg
's self-description states that it provides examples of common uses of command line tools. I checked how well this works.
Quickly Installed
To do so, I first visited the tool's GitHub page [1] to see what the install looks like. The tool is not available from the package archives of most of the popular Linux distributions. You can install it with pip
, the package installer for Python packages from the Python Package Index. But to do this, you may first need to install the python3-pip package on your machine from the package manager, if it is not already in place. You then retrieve eg with the pip install eg
command and store it on your hard disc.
Once eg
is installed and ready to use, there is no need for configuration, but it is possible. As your first official step, type the eg --list
command, which shows you an alphabetically sorted list of the 80 or so tools and commands currently supported (Figure 1). If the system outputs a command not found message when you do this, you will probably have to log off the desktop and log back on again. The system will then include the installation directory in its path.
![](/var/linux_magazin/storage/images/issues/2022/258/command-line-tool-examples/figure-1/803717-1-eng-US/Figure-1_large.png)
Examples of one of the listed commands are easy to access by calling eg NAME
. You will notice that some entries have only a few lines (Figure 2), while others – such as the entry for Git – have several hundred lines. Once you have finished reading an entry, pressing Q will return you to the prompt. If you do not want to continue using eg
after a test, simply remove it by typing pip uninstall eg
.
![](/var/linux_magazin/storage/images/issues/2022/258/command-line-tool-examples/figure-2/803720-1-eng-US/Figure-2_large.png)
Scope for Your Own Ideas
eg
stores in $HOME/.local/lib/python3.9/site-packages
. Check out the "Installation Path" box for more details. In the installation directory, you will find the supported commands and tools below the eg/examples/
folder in Markdown format. If you want to add examples or parameters yourself, open the corresponding Markdown file and make your changes.
Installation Path
You install eg
in $HOME/.local/lib/
, and the executable is located in $HOME/.local/bin
. You need to make sure that this directory is in your path variable. You can determine whether this is the case by typing echo $PATH
. If the directory is missing from the list, you can add it temporarily by typing export PATH="$HOME/.local/bin:$PATH"
. But this configuration will not survive the next reboot. Use the entry shown in Listing 1 to store it permanently in your $HOME/.profile
. Most desktop environments preconfigure the shell appropriately. But the if
query in Listing 1 only integrates the path if the directory already exists at login time. You may need to log out and back on again after installing eg
.
Listing 1
~/.profile
[...] # set PATH so it includes user's # private bin if it exists if [ -d "$HOME/.local/bin" ]; then PATH="$HOME/.local/bin:$PATH" fi [...]
Also, eg
lets you store your own entries in the data structure. To do this, create a file named NAME.md
in examples/
, and eg
will load it automatically from there. Ultimately, the tool does nothing more than match a command you type, such as eg git
, with the files in the default and custom directories (including subfolders). If eg
finds a matching entry, it outputs the entry, piping it through the less
pager (Figure 3) to do so.
![](/var/linux_magazin/storage/images/issues/2022/258/command-line-tool-examples/figure-3/803723-1-eng-US/Figure-3_large.png)
If you want to organize your own creations in a separate directory, create a configuration file named $HOME/.config/eg/egrc
or $HOME/.egrc
. In the simplest case, this will look something like Listing 2. You can also define an alternate location for the default examples/
directory. The output can also be extensively customized to suit your own needs, for example, by adding colors. Examples of this can be found on the project's GitHub page [1].
Listing 2
Configuration
[eg-config] custom-dir = $HOME/my-eg
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.