Using ChatGPT to Generate Somewhat Complex Unix Commands

Using Chat GPT To Generate Complex Unix Commands

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

command line screenshot

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

About the Author

Picture of Aaron Reimann

Aaron Reimann

Aaron is a PHP developer who started and sold an agency called Sideways8.com. He is currently running Clockwork, a website design, development and hosting shop. He has built sites for companies of all shapes and sizes, ranging from small nonprofits to Fortune 100 companies, since beginning his work with WordPress in 2008. An organizer for WordCamp Atlanta and the Atlanta WordPress Meetup, Aaron provides leadership and speaks regularly at events around the world.
Picture of Aaron Reimann

Aaron Reimann

Aaron is a PHP developer who started and sold an agency called Sideways8.com. He is currently running Clockwork, a website design, development and hosting shop. He has built sites for companies of all shapes and sizes, ranging from small nonprofits to Fortune 100 companies, since beginning his work with WordPress in 2008. An organizer for WordCamp Atlanta and the Atlanta WordPress Meetup, Aaron provides leadership and speaks regularly at events around the world.