The moreutils collection
Charly's Column – moreutils
This month, sys admin columnist Charly dumps the moreutils toolbox on his workbench and takes combine and vidir for a spin.
In the March 2013 issue, I wrote about ifdata
, which gives you information about networks in a way that is great for scripting. I had taken the tool from the moreutils package at the time; this toolbox comes with almost every flavor of Linux, and, if not, you can download it [1]. Further investigation of the package reveals even more laser-sharp tools. For instance, combine
is really practical for comparing stuff. You need to pass in the names of two text files and a logical operator: and
, not
, or
, or xor
(exclusive or).
As an example, I created two text files with IP addresses and networks. Some of the addresses and networks are included in both files, while others are not. Now I let combine
compare the files, first with the and
operator:
combine iplist-a.text and iplist-b.text
In Figure 1, you can see the content of the two files, and then the combine
command line. The output I got was all the lines that occur in both files.
When I executed the command with the or
operator, I could see everything that occurred in one or both the files. Important: If a line appears in both files, it also appears twice. This is often undesirable, but can be suppressed with:
combine iplist-a.text or iplist-b.text | sort | uniq
One thing is probably already clear to most readers: The same results are possible with cat
, but many roads lead to Rome. Using the not
operator, I can output all the lines that occur in the first file, but not in the second. The xor
operator tells combine
to return the lines that are only found in one file, but not in both.
Sly List
Another workhorse from the moreutils package goes by the name of vidir
. I don't use it often, but if I do, it saves a huge amount of typing. (Praise be to anything that contributes to my laziness.) vidir
in particular makes it easier to rename files. Normally, I do this with:
mv <File_1> <File_2>
The Perl rename
tool does this more conveniently and can process multiple files at the same time. But vidir
has a special trick up its sleeve. When I run it in the current directory, it opens Vi (or whatever $EDITOR
defines) and displays a list of the files present in the directory. Now I can edit the file names to suit my needs. In Figure 2, I renamed the iplist
files from the earlier example. When I leave the editor and run ls
, hey presto, I find the files have been renamed.
This excursion has by no means exhausted the moreutils box – in fact, it comprises 17 tools. Some only do tiny jobs (e.g., isutf8
checks whether a file is valid UTF-8); others are more extensive – some great DIY stuff included!
Infos
- moreutils: https://joeyh.name/code/moreutils/
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.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.