Skip to main content

AI for Linux

Chapter #4: How to Use TerminalGPT for AI Assistance in Linux

Learn how to install and use TerminalGPT, a terminal-based ChatGPT personal assistant app for Linux, to boost productivity in your daily sysadmin tasks.

If you follow along with this series, where we try to add the power of AI to Linux through various available AI tools, you will discover many that can be used in the terminal.

However, the problem with most of them is that they require an API key, and for most LLMs, using the API key is not free and requires payment. Having a tool that gives us the power of AI at no cost would be a game-changer.

TerminalGPT offers the useful option of using AI without requiring an API key, which also allows us to choose which LLMs to use, as it supports multiple models.

In this guide, we’ll learn how to install and use TerminalGPT, along with examples and use cases that demonstrate how to apply it to our daily sysadmin tasks.

What is TerminalGPT

TerminalGPT, or tgpt, as the name suggests, is a terminal tool that integrates with the command line and is used for daily tasks, offering many capabilities and use cases.

Eliminating the need for an API key in some cases, tgpt includes many features such as:

  • Generating text
  • Generating code and executing shell commands
  • Generating images

And much more can be done using this tool.

TGPT is written in Go, which makes it powerful and high-performing. It supports various LLMs like Blackbox, DeepSeek, OpenAI, Grok, and more.

You can choose the one that suits your needs. Some models, like DeepSeek and OpenAI, require an API key, while others do not. You can find more information about the tool on its official GitHub repository.

Install Terminal GPT in Linux

The installation of the tool itself is simple and doesn’t require any dependencies. Simply run the following curl command:

curl -sSL https://raw.githubusercontent.com/aandrew-me/tgpt/main/install | bash -s /usr/local/bin

This command works for Linux and macOS. Also, if you have Go installed on your machine, which I think you do, you can easily install it via the Go package manager with the command:

go install github.com/aandrew-me/tgpt/v2@latest

This will directly install and add the tool to your system shell path.

In case you want to update the tool, simply run the command:

tgpt -u

After the installation, you can check if it’s working properly with the command tgpt -h, which will give you an output like this:

Confirm TerminalGPT Installation

To check if it’s working and can answer questions, run this example: tgpt "What is Tecmint?" and you should get an answer like this:

Test If TerminalGPT Is Working

That means the AI tool is installed, and you can start using it in the terminal.

Use Cases of TerminalGPT in Linux

As a system admin or a developer, TGPT is useful in many cases and scenarios where you need extra help to complete a task or even to understand or debug a shell script or any code in general.

Code Explanation and Correction

Like other AI tools, such as Fabric AI, TGPT can assist you with code explanations, completion, or debugging, which will save time spent on debugging and refactoring code.

Let’s do an example where we need a shell script to schedule a cron job to do a backup every day of the /var/www folder.

Creating a script like this will take some time, especially if you are new to shell scripting. With TGPT, it will take 10 seconds, I guess, and the prompt will be like this:

tgpt "create a shell script to schedule a cron job that performs a daily backup of the /var/www folder"

And in a matter of seconds, we get a result like this:

Create Shell Scripts Instantly Using TGPT

Another example: Sometimes, you create a shell script, and it doesn’t work properly or doesn’t work at all, and you can’t figure out where the error is. TGPT is here for you, where you can pass the code and get the error fixed.

For example, I have a script called mybash.sh with the following content:

#!/bin/bash
 
BACKUP_DIR="/backup"       
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_FILE="$BACKUP_DIR/home_backup_$TIMESTAMP.tar.gz"
SOURCE_DIR="/home/$USER"    
 
mkdir -p "$BACKUP_DIR"
tar -czf "$BACKUP_FILE" "$SOURCE_DIR"
echo "Backup completed: $BACKUP_FILE"

In this code, there is one simple error, but it may not be visible to you if you don’t pay attention. What we can do is pass the file to GPT and ask it to fix it.

tgpt "What is the problem in this code? $(cat mybash.sh)"

Here, we use a pipe (|) to pass the output of the cat command, which reads the file, to TGPT and asks for help.

The output will be like this:

Fix Broken Shell Scripts Instantly with TerminalGPT

Another way to pass the file is like this:

cat mybash.sh | tgpt "What is the problem in this code?"

This will make sure TGPT reads the file correctly.

That’s just a simple example; you can pass any complex code, and TGPT will debug it for you.

Create and Execute Shell Commands

Another helpful feature of TGPT is that it can help you manage your system. If you are a total beginner in the world of Linux, this tool will help you achieve daily tasks like updating software, installing new packages, and so on. TGPT will generate the command and ask you if you want to execute it.

Let's say, for example, you want to update the system but don't know how to do it. You can simply ask:

tgpt "How to update my system?"

If you want to add command execution, use the -s flag like this:

tgpt -s "How to update my system?"

The output will be like this:

Let TGPT Handle the Commands for You

First, it will display the command, and then it will ask if you want to execute it. You can choose y or n as you prefer.

Git & Version Control

Another use case for the TGPT tool is using it with Git. It can assist you throughout your Git workflow.

Suppose you are a Git beginner and have a code repository that you need to commit to GitHub, but don’t know the steps. You can simply create a prompt like this to ask AI for help:

tgpt "How do I initialize a Git repository, commit my code, and push it to GitHub?"

This will guide you through the steps to commit code to GitHub:

Learn Git Faster with TGPT

Generate Images from Linux Terminal

This is less useful for a system admin, but it may be helpful in cases where you need to generate an image from text. TGPT also offers this option inside your terminal.

For example, if you need an image with the name of your company and other details, you can use the following command:

tgpt -img "Create an image with the title 'TecMint.com' at the top, featuring the Linux logo in the center. Use a smooth gradient background."

The TGPT tool is helpful for many things, and you can use it as you like, all for free and inside the terminal. To unlock more powerful features, you can add an API key for OpenAI or DeepSeek to access advanced capabilities.

Conclusion

This guide explained how to install and use the AI terminal tool TGPT. We also shared some use cases and examples where this tool can be highly beneficial.

Feel free to keep exploring and using it in different situations.