TranslateProject/sources/tech/20230415.3 ⭐️⭐️ Generate Linux Commands from English Text Using ChatGPT AI.md

6.1 KiB

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.

Shell Genie AI assistent in Linux terminal

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.

Shell Genie explain commands

Features of Shell-Genie

  • Convert plain English to Linux Commands.
  • Provides an openAI gpt3 backend that requires an API key from openAI and a free-genie backend that is free to use.
  • Prompt with an option to run the command you asked for.
  • 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

An SVG animation showing pipx Installation steps

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.

A dependency installation to install the shell-geie properly

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.

The steps showing the installation of shell-genie

Once installation is complete, run the following:

shell-genie 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.

Run shell-genie init commad to set up the shell-genie properly

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.

  • Get command from plain English
  • 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.

The working of shell-genie, that will print the required command from the provided plain text description. Also propt the user to execute the same or not

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.

The explain mode in shell-genie, where it will explain the command that was asked in the form of plain english and then prompts the user to execute it or not

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.


via: https://itsfoss.com/linux-terminal-ai/

作者:Sreenath 选题:lkxed 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出