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.
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.
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
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.
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.
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.
It will then ask permission to report feedback. Decide on that with a y/n
.
You are ready to go now.
Working with Shell-genie
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.
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.
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.