These Linux programs embody simplicity, elegance and of course, do one thing really well
If you peek under the hood of Linux you’ll find a treasure trove of built-in programs. Many of these default programs follow a rule called the Single -responsibility Principle. This means that they do one thing and they do it quite well.
These utilities don’t try to pack on countless features or support every possible format or style. They are unapologetic and unforgiving. They serve a purpose and perform one function and that’s all. It is exactly for this reason that they are beautifully elegant. In today’s world of over-hyped multitasking, multi-functional and feature-bloated applications the simplicity and effectiveness of a small Linux program is like a comforting, warm blanket.
No convoluted user interfaces, no sifting through hundreds of stapled together features. Just a pure approach.
Let’s take a look at some fantastic examples of Linux programs exemplary of this pragmatic, utilitarian world.
About as simple as it gets. There are only four accepted parameters to this command, one being the
--help flag. The
sum utility will produce a checksum and block count for the specified input file.
Let’s make a simple text file with the following content:
And run it through the
> sum file.txt
On the left is the checksum for the file and the right is the number of blocks it occupies in the filesystem. Brutally simple.
This is useful for performing a quick differential between files or checking to see if a file has been changed since the last checksum.
Also check out the
cksum utility to perform a checksum and count the bytes instead of blocks.
This utility allows you to create temporary files. Sometimes you need to store a bit of information in a file until a process has completed. In order to do this quickly and safely you can simply use the
Rather than setup file creation in the
/tmp directory manually, using
mktemp you get everything done for you in one simple command. This prevents you from having to check if the file already exists or select a unique filename.
mktemp will produce the name and path of your new temp file:
Now when you need to store some data in a temp file you won’t have to reinvent the wheel. Let Linux do it for you.
Path diving on Linux can become quite complex. Especially if you’re following a handful of symlinks around. The
namei The utility will show you the hierarchy of a single path and the twists and turns it takes to get to the end of it.
For example, let’s say we have a directory with a test file inside it:
We’ll create a symlink to this directory called
symlink_dir and then use
namei to determine the path to the test file via the symlink:
l symlink_dir -> /tmp/real_dir
As you can see,
namei shows us the full path we take to end up at the
test_file inside of
real_dir. This includes traversing the
symlink_dir and pointing back at
Rather than use something like
ls to tediously dig into each directory or potential symlink in your path you can use
namei and get a clear picture immediately.
Whether you know this command already or not, the incredible usefulness of it is huge. The
sg The utility allows you to switch groups and execute a command as that group. For example, if you wanted to execute something as the
admin group but your user isn’t a member of it. To do this you could use:
sg admin 'ls -lah'
This will execute
ls -lah as the
admin group and then immediately return you to your original group membership.
sg command is great for things like testing overall group permissions or running scripts with different privileges.
Security is paramount on any Linux machine, especially if its located in the cloud. If you think someone may have logged into a particular host and performed some malicious activity or errant command, the
last utility can help.
tate pts/0 188.8.131.52 Wed Jan 26 01:17 still logged in
tate pts/0 184.108.40.206 Wed Jan 26 01:17 still logged in
tate pts/0 220.127.116.11 Wed Jan 26 01:04 - 01:04 (00:00)
tate pts/0 18.104.22.168 Wed Jan 26 01:01 - 01:02 (00:01)
tate pts/0 22.214.171.124 Tue Jan 25 20:55 - 00:00 (03:05)
last you can see the login activity of all users and key information like their remote IP, login time and current status.
Also note how
last shows you the duration of each session. If there is a high number of extremely short duration sessions, it may mean some script or automated system is logging in and out of your system. This may help you track down any suspicious or unwanted activity occurring on your system.
Everyone knows the
cat command. It is one of the first commands other than
ls that you probably used on Linux. But do you know the
cat command’s evil twin?
tac command (which is literally “cat” spelled backwards) does almost the exact same thing as
cat. It still displays the contents of a file, but now it does it backwards.
For example, let’s say I had a file with the following in it:
cat this file, the usual output appears. If I
tac the file I get this:
Sure, this may seem silly at first, but imagine you had a rather large log file and wanted to display its contents starting from the most recent entry. Using
tac You can easily feed the output of such a log file into either your console or another application for processing.