Sabtu, 15 April 2023

Generate Linux Commands from English Text Using ChatGPT AI

Generate Linux Commands from English Text Using ChatGPT AI

Even expert Linux users don't remember all the Linux commands and their options. It's not possible for us humans.

But what about the machine? Especially the AI-powered machine?

Imagine if you could 'order' your terminal to 'show all files under 100 MB in size that were modified in last 12 hours'. Sure, you can 'order' it using the Linux commands but what about interacting with in plain English?

Thanks to the advancement of AI, it is actually possible. Here's an example of automatically generating the Linux command to show all the files smaller than 10 KB in the present directory.

Generate Linux Commands from English Text Using ChatGPT AI

The tool I am using is called Shell Genie. It is a command-line tool that lets you interact with the terminal in plain English.

It can generate commands, run the commands (if you want to), and it can also explain the generated commands to you.

Generate Linux Commands from English Text Using ChatGPT AI
AI can explain how the command works

Features of Shell-Genie

  1. Convert plain English to Linux Commands.
  2. Provides an openAI gpt3 backend that requires an API key from openAI and a free-genie backend that is free to use.
  3. Prompt with an option to run the command you asked for.
  4. Explains the generated commands.

Install Shell Genie

Shell-genie is not available in the default repositories of any distro. You can install it using pipx.

In order to install, you need to have Python 3.10+ and Pip installed. You can refer to our article on how to install pip in Ubuntu and other Linux distributions.

Once pip is installed, install pipx with the following command:

python3 -m pip install --user pipx
python3 -m pipx ensurepath
Generate Linux Commands from English Text Using ChatGPT AI
Install pipx 

Now, restart the terminal and install shell-genie by running:

pipx install shell-genie

This may show an error or the need for a dependency.

Generate Linux Commands from English Text Using ChatGPT AI
Dependency Required notification

Run the command that is prompted to install the required dependency. In my case:

sudo apt install python3.10-venv

After this, run the shell-genie install command once more, and it will be installed.

Generate Linux Commands from English Text Using ChatGPT AI
Install `shell-genie`

Once installation is complete, run the following:

shell-gnie init

This will ask you to select the backend, either openAI or free-genie. If you have openAI API, you can choose that or stay with the free-genie.

🚧
free-genie backend may not work always, because it is hosted by the developer, and he cautions of possible outages.

It will then ask permission to report feedback. Decide on that with a y/n.

Generate Linux Commands from English Text Using ChatGPT AI
Run shell-genie init

You are ready to go now.

Working with Shell-genie

🚧
If you are going to experiment, try not to use commands with sudo or remove files. Don't put your machine in the hands of a machine.

As said above, shell-genie provides two modes for working.

  1. Get command from plain English
  2. Get command explanation

Get Linux commands from plain English

You can use shell-genie's ask option to get commands from plain English. For eg.

shell-genie ask "Display only the folders of this directory"

This will display the proper command, and prompt us to run the command or not.

Generate Linux Commands from English Text Using ChatGPT AI
Shell-genie working

Get Linux commands with explanation

You can use shell genie to explain some commands that you want to run.

shell-genie ask "display all files smaller than 10kb in here" --explain

The above command will first display the required command and explains it and then prompts the user to execute it or not.

Generate Linux Commands from English Text Using ChatGPT AI
Shell-genie in explain mode

Wrapping Up

There are tools like Explain Shell that (try to) explain the Linux commands. But this Shell genie takes it to the next level by generating commands from plain English.

Of course, you cannot rely on artificial intelligence blindly. If you are familiar with the Linux commands a little, you can use Shell Genie to generate commands for your purpose. You won't have to struggle with the man pages or various websites.

It sorts of helps you do things faster in the terminal and also makes you less knowledgeable. Why? Because the more you rely on it, the less you will learn on your own.

That's what I think. Feel free to agree or disagree with me in the comments.



from It's FOSS https://ift.tt/zpm8WRC
via IFTTT

Tidak ada komentar:

Posting Komentar