服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - 使用 ChatGPT AI 从英文文本生成 Linux 命令

使用 ChatGPT AI 从英文文本生成 Linux 命令

2023-05-08 13:55Linux中国Sreenath Linux

我使用的工具叫做 Shell Genie。它是一个命令行工具,可让你以普通的英语与终端进行交互。

使用 ChatGPT AI 从英文文本生成 Linux 命令

即使是专家级的 Linux 用户也不记得所有的 Linux 命令和它们的选项。这对我们人类来说是不可能的。

但是机器呢?尤其是人工智能驱动的机器?

想象一下,如果你可以“命令”你的终端“显示过去 12 小时内修改过的所有小于 100 MB 的文件”。当然,你可以使用 Linux 命令“命令”它,但是用普通的英语进行交互呢?

由于人工智能的进步,这实际上是可能的。下面是自动生成 Linux 命令以显示当前目录中所有小于 10 KB 的文件的示例。

使用 ChatGPT AI 从英文文本生成 Linux 命令

Shell Genie AI assistent in Linux terminal

我使用的工具叫做 Shell Genie。它是一个命令行工具,可让你以普通的英语与终端进行交互。

它可以生成命令、运行命令(如果需要),还可以向你解释生成的命令。

使用 ChatGPT AI 从英文文本生成 Linux 命令

Shell Genie explain commands

Shell-Genie 的特点

  • 将普通英语转换为 Linux 命令。
  • 提供了一个需要 openAI 的 API 密钥的 openAI gpt3 后端,和一个可以免费使用的 free-genie 后端。
  • 提示一个选项以运行你要求的命令。
  • 解释生成的命令。

安装 Shell Genie

Shell-genie 在任何发行版的默认仓库中都不可用。你可以使用

pipx 安装它。

要安装它,你需要安装 Python 3.10+ 和 Pip。你可以参考我们关于 如何在 Ubuntu 和其他 Linux 发行版中安装 pip 的文章。

安装

pip 后,使用以下命令安装

pipx:

python3 -m pip install --user pipx python3 -m pipx ensurepath

使用 ChatGPT AI 从英文文本生成 Linux 命令

An SVG animation showing pipx Installation steps

现在,重启终端并运行以下命令安装 shell-genie:

pipx install shell-genie

这可能显示错误或需要依赖项。

使用 ChatGPT AI 从英文文本生成 Linux 命令

A dependency installation to install the shell-geie properly

运行提示的命令来安装所需的依赖。在我的例子中:

sudo apt install python3.10-venv

之后,再次运行

shell-genie 安装命令,就可以安装了。

使用 ChatGPT AI 从英文文本生成 Linux 命令

The steps showing the installation of shell-genie

安装完成后,运行以下命令:

shell-genie init

这将要求你选择后端,openAI 或 free-genie。如果你有 openAI API,你可以选择它或继续使用 free-genie。

free-genie 后端可能并不总是工作,因为它是由开发者托管的,他警告说可能会出现中断。

然后它将请求允许报告反馈。用

y/n 来决定。

使用 ChatGPT AI 从英文文本生成 Linux 命令

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

现在就可以使用了。

使用 Shell-genie

如果你要进行实验,请尽量不要使用带有

sudo 或删除文件的命令。不要将你的机器交到机器手中。

如上所述,shell-genie 提供了两种工作模式:

  • 从普通的英语获取命令
  • 获取命令解释

从普通英语中获取 Linux 命令

你可以使用 shell-genie 的

ask 选项从普通的英语中获取命令。例如:

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

这将显示正确的命令,并提示我们是否运行该命令。

使用 ChatGPT AI 从英文文本生成 Linux 命令

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

获取带解释的 Linux 命令

你可以使用 shell genie 来解释你要运行的一些命令。

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

上面的命令首先会显示需要的命令并进行解释,然后提示用户是否执行。

使用 ChatGPT AI 从英文文本生成 Linux 命令

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

总结

有像 Explain Shell 这样的工具(试图)解释 Linux 命令。但是这个 Shell genie 通过从普通的英语生成命令将它提升到一个新的水平。

当然,不能一味依赖人工智能。如果你对 Linux 命令有一定的了解,可以使用 Shell Genie 生成适合你的命令。你不必为手册页或各种网站而苦恼。

它可以帮助你在终端中更快地做事,也可以减少你的知识储备。为什么? 因为你越依赖它,你自己学的就越少。

(题图:MJ/chatgpt commands linux cli illustration in high resolution, very detailed, 8k)

原文地址:https://linux.cn/article-15764-1.html

延伸 · 阅读

精彩推荐