= 5 Perl scripts you can't live without

Before Python was the ubiquitous multitool of computer programming, Perl was the first choice for hobbyist programmers and lazy sysadmins.
A lot of everyday Linux utilities in use today were written in Perl, so whether you're using Perl as a scripting language or not, you're probably still using Perl programs.
It's easy to overlook, though, because you usually don't think about commands in terms of what language they're written in.
I sometimes find gems while browsing CPAN (the PyPi of Perl), and here are 5  of my favourite Perl utilities.

== mimetype

A mimetype is a standard way to identify a file system entity.
On the Internet, mimetypes help browsers understand what generic icon to assign a file, and they help desktops know what kind of application to use when opening a file.
Unless you use them often, though, it can be difficult to recall the official mimetype designation for a filetype.
The Perl script `mimetype`, in the `perl-file-mimeinfo` package, provides the quickest and easiest solution:

[source,bash]
----
$ mimetype example.txt
example.txt: text/plain
$ mimetype html/example.webp
html/example.webp: image/webp
$ mimetype mydir
mydir: inode/directory
----

== innotop

You know `top`, `htop`, maybe `powertop`.
But if you run databases, then you need to know `innotop`.

The `innotop` command monitors a MySQL or MariaDB database, providing you with performance and I/O statistics (including memory usage and queries processed per second), replication status, a query list, and much more.

You can get `innotop` from the MariaDB package.

== inxi

Linux has plenty of commands to get a profile of your system.
There's ``lsblk` for block devices, `free` for RAM, `ip link` for network interfaces, and so on.
But if you're looking for a unified command to give you just the information you want, then you have to try `inxi`.

The `inxi` command gives you the information you expect when you go to get the specs of a computer:

[source,bash]
----
CPU: 6-core AMD Ryzen 5 5600X (-MT MCP-)
speed/min/max: 2248/2200/4650 MHz
Kernel: 5.15.38 x86_64
Up: 9h 32m
Mem: 7684.2/32104.6 MiB (23.9%)
Storage: 7.28 TiB (48.1% used)
Procs: 517 Shell: Bash inxi: 3.3.12
----

Nine out of ten times, that's the information you really mean to get, and `inxi` provides it so that it's easy to read, and easy to copy and paste.
That's not all `inxi` does, though.
There are plenty of extra options available in its man page.
For instance, I do a lot of audio work when I can, so seeing a full list of audio devices is nice:

[source,bash]
----
$ inxi --audio
Audio:
  Device-1: NVIDIA GP107GL High Definition Audio driver: snd_hda_intel
  Device-2: AMD Starship/Matisse HD Audio driver: snd_hda_intel
  Device-3: Logitech StreamCam type: USB
    driver: hid-generic,snd-usb-audio,usbhid,uvcvideo
  Device-4: Cooler Master CH321 type: USB
    driver: hid-generic,snd-usb-audio,usbhid
  Device-5: Logitech HD Pro Webcam C920 type: USB
    driver: snd-usb-audio,uvcvideo
  Device-6: ZOOM Handy Recorder stereo mix type: USB
    driver: snd-usb-audio
  Sound Server-1: ALSA v: k5.15.38 running: yes
  Sound Server-2: PulseAudio v: 15.0 running: yes
----

It's a great tool to have on any system, so go https://github.com/smxi/inxi[download inxi] now.

== parallel

I've written about my love of https://origin-sysadmin.redhat.com/gnu-parallel[GNU Parallel] before, but it's worth another mention.
The `parallel` command literally means you can do more work, faster, with fewer commands.
And it has two separate entry points: You can use it as the recipient of output sent through a Unix pipe, or as a stand-alone command.

As a piped command, the typical start is the `find` command:

[source,bash]
----
$ find ~/public_html/images -type f -name "*jpg" | \
parallel convert {} {.}.webp
----

This command finds all JPEG images in the `public_html/images/` folder and converts them, in parallel, to WEBP (and swaps the extension `.jpg` for `.webp` in the process).

The stand-alone version of the command looks a little more mysterious if you're not used to it.

[source,bash]
----
$ parallel ffmpeg ~/Audio/file.flac -vn ~/Audio/file.{} ::: ogg m4a opus
----

This command uses `ffmpeg` to convert audio to three different formats.

Parallel is a must-have on any system, and is available from your software repository.

== exiftool

It happens all the time.
A user uploads a photo containing all kinds of potentially sensitive information in its metadata.
Nobody gives it a second thought until somebody thinks to dump the EXIF data on the photo, which provides longitude, latitude, dates, and sometimes even more information about the person who took the picture.
You can help protect your users (and yourself) by scrubbing EXIF metadata from photos before those photos are made public.
The classic tool for that is the Perl script `exiftool`.

This command removes all metadata from all photos in the `~/public_html/images` directory:

[source,bash]
----
$ exiftool -overwrite_original \
-all:all= \
-r ~/public_html/images/
----

Of course, `exiftool` is useful for more than just deleting all metadata.
You can write new metadata with it, or correct metadata that's wrong.
For instance, sometimes the EXIF data on a photo requests the photo viewer to rotate the image.
When that's not what you want, you can set the `Orientation` property.
There are 8 possible values for orientation:

1. Horizontal (normal)
2. Mirror horizontal
3. Rotate 180
4. Mirror vertical
5. Mirror horizontal and rotate 270 CW
6. Rotate 90 CW
7. Mirror horizontal and rotate 90 CW
8. Rotate 270 CW

For example:

[source,bash]
----
$ exiftool -Orientation=1 ~/public_html/image/foo.jpg
----

There are lots of possible properties in EXIF, so it can be difficult to know what values are expected.
The `exiftool` project maintains a friendly https://exiftool.org/TagNames/EXIF.html[conversion table] for quick reference.

== Perl is a gem

You may not hear as much about Perl as you used to, but that doesn't mean the project's irrelevant.
For me, Perl is a great "Bash++" language, with many conventions that feel similar to a C-like or shell scripting language than Python does.
Even if you don't intend to write Perl scripts yourself, though, the five scripts I've listed in this article is just the beginning of a collection of amazing utilities you should be using on your system.
Try them out!
