关于linux:Linux-瑞士军刀-BusyBox-实用工具

8次阅读

共计 1577 个字符,预计需要花费 4 分钟才能阅读完成。

BusyBox 是一个不便的实用工具,它在一个大概 2 MB 的可执行文件中提供了几个精简的 UNIX shell 命令行工具和微型 Linux 程序汇合。它能够在多个环境中运行,如 Android、Linux、FreeBSD 等环境。BusyBox 是专门为内存和存储空间十分无限的嵌入式设施而创立的。

BusyBox 被称为瑞士军刀工具,它是 GNU shellutils、fileutils 和 coreutils 中 shell 实用程序的简略代替。它也能够在占用空间较小的 Linux 发行版中找到,比方 Alpine Linux。

在本指南中,咱们将帮忙您在 Linux 上开始应用 Busybox。

装置 BusyBox

对于 Debian / Ubuntu 零碎,执行如下命令

$ sudo apt update
$ sudo apt install busybox

对于 ArchLinux / Fedora /RHEL / CentOS / Rocky / AlmaLinux 零碎

首先下载 BusyBox 64 位二进制文件

$ wget https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64

接下来,给它起一个更简略的名字

$ mv busybox-x86_64  busybox

而后应用 chmod 命令为其调配执行权限

$ chmod +x busybox

运行 BusyBox 并查看其版本,应用和以后反对的性能,请运行命令

$ busybox

BusyBox 也能够作为 Docker 容器映像应用,确保您曾经装置了 Docker

要拉取 BusyBox 映像,运行如下命令

$ sudo docker pull busybox

要确认 BusyBox 映像的存在,运行如下命令

$ sudo docker images

拜访 BusyBox shell

要从 BusyBox 容器映像拜访 BusyBox shell,运行如下命令

$ sudo docker run -it --rm busybox

如果您从二进制文件或应用 APT 装置 BusyBox,您能够按以下形式拜访 shell

$ busybox sh

试用 BusyBox

要应用 BusyBox 的工具或 applet,在 BusyBox shell 中,须要在命令前加上 busybox 关键字,语法如下:

$ busybox command

大概有 400 个命令和程序可供使用,能够应用如下命令查看

$ busybox --list | wc -l

要列出当前目录门路下的文件和文件夹,只需运行

$ busybox ls -l

你能够尝试 ping 一个域名,如 google.com

$ busybox ping -c google.com

应用 Httpd WebServer

One of the tiny Linux programs that BusyBox provides is the httpd webserver. You can confirm this by running the command:

BusyBox 提供了 httpd web 服务器,能够通过运行命令确认

$ busybox --list | grep httpd

要启动一个 web 服务器,请用 root 用户拜访 Busybox shell

# busybox sh

运行如下命令,激活 webserver

# busybox httpd

运行如下命令,确认 webserver 过程正在运行

# ps -ef | grep httpd

接下来,咱们将创立一个简略的 HTML 文件,用于测试 web 服务器。

# busybox vi index.html
<!DOCTYPE html>
<html>
<body>
Welcome to BusyBox !
</body>
</html>

关上浏览器,拜访 localhost,浏览器输入如下所示

我的开源我的项目

  • course-tencent-cloud(酷瓜云课堂 – gitee 仓库)
  • course-tencent-cloud(酷瓜云课堂 – github 仓库)
正文完
 0