Using ChatCPT to Generate Somewhat Complex Unix Commands

by Aaron Reimann

March 20, 2024

The command-line interface provided by *nix (Unix, Linux, BSD, etc.) systems is undeniably a powerful tool for developers and system administrators alike. With its intricate, flexible syntax, one can accomplish a vast array of tasks that might otherwise be time-consuming or complicated using other methods. For instance, I recently found myself in a situation where I had to download a backup of a website and then selectively retrieve all of the .pdf, .doc, and .docx files, later transferring them to a new site. While I possess a decent amount of familiarity with the command-line, the task at hand was probably going to take some research. This is the command I came up with:

find . -type f ! \( -name "*.doc" -o -name "*.docx" -o -name "*.pdf" \) -exec rm -f {} +

Instead of trying different configurations, I decided to send this need to ChatGPT and not only did it come up with that one-liner (above), it also explained the command. It also gave me a way to do a test to see what all would be removed before I ran the “destructive” mode:

find . -type f ! \( -name "*.doc" -o -name "*.docx" -o -name "*.pdf" \) -print

The amount of time this can save me is pretty amazing.

related posts

Celebrating 20 Years of WordPress by Speaking at WordCamp Europe 2023

Now that I’ve settled down from my trip to Israel and Greece, I wanted to…

Speaking at WordCamp Netherlands 2022

In the WordPress world, we have WordCamps. It is an event that will have 150…

We’re Using Rocket.Chat

In 2014 or 2015 we started off using Hipchat. Hipchat was pretty cool, but this…