DEV Community

Cover image for Exploring ChatGPT's Magic in the Linux Command Line
Rahul Kumar Sharma
Rahul Kumar Sharma

Posted on

Exploring ChatGPT's Magic in the Linux Command Line

Integrating ChatGPT into the Linux terminal opens a world of possibilities for natural language interactions and automation. By combining the power of OpenAI's ChatGPT with the flexibility of the Linux terminal, users can harness the capabilities of this language model for a wide range of tasks and applications.

ShellGPT:

Users can communicate with the AI chatbot on their Linux terminal using ShellGPT, a command line interface for ChatGPT. It is based on the GPT large language model from OpenAI.

Based on our text input, ShellGPT can provide intelligent suggestions and recommendations and even run shell commands. Additionally, it gains knowledge from our exchanges and improves with time. Users no longer need to input lengthy commands or memorize difficult Linux Terminal commands thanks to the ChatGPT application included into the command line. By having ChatGPT handle part of their tedious labor on their behalf, they may reduce errors while saving critical time.

Prerequisites to install ChatGPT in Linux:

  1. AWS account
  2. Create an EC2 Instance(Ubuntu).

Steps:

a. Create an EC2 instance and SSH into it.

EC2Instance

b. Check if Python is installed in it or not.

check python version

c. Install PIP and check the version.

Install PIP

PIP Version

d. Install venv.

Install venv

e. Setup ShellGPT to use ChatGPT.

  1. Setup environment.
  2. Create a directory.

mkdir

  1. Create a virtual environment.

create virtual env

  1. Activate the env.

activate env

f. To get OpenAI API Key, navigate to OpenAI’s website.

OpenAi

g. Click on profile and select View API Keys.

profile

h. Click on Create new Secret key.

create key

i. Copy the Key and save it.

j. Now, create an environment variable for this API key with the command below. In Linux, you can create an environment variable using the “export” command.

Replace placeholder with the actual API key you generated to use ChatGPT in the Linux terminal.

export OPENAI_API_KEY=sk-YHhk0****************RMVLVZdqQjiNZ

export

k. To verify if the export is successfully use env.

verifyexport

l. To store variable permanently, open .bashrc file and add the API key.

bashrc

m. To make commands in effect, run the command: source .bashrc .

commandeffect

n. Install ShellGPT.

InstallShellGPT

o. Now that we have install ShellGPT, we can use it.

Syntax:

chat Syntax

Options Description
--temperature Changes the randomness of the output
--top-probablity Limits to only the highest probable tokens or words
--chat Used to have a conversation with a unique name
--shell Used to get shell commands as output
--execute Executes the commands received as output from --shell option
--code Used to get code as output

In Action:

OP1

OP2

Let's Connect!

Top comments (0)