Linux 瑞士军刀 - BusyBox 实用工具

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



Welcome to BusyBox !

打开浏览器,访问 localhost,浏览器输出如下所示

我的开源项目

酷瓜云课堂 - 开源在线教育解决方案

展开阅读全文

页面更新:2024-03-20

标签:映像   容器   实用工具   仓库   瑞士军刀   课堂   命令   简单   环境   服务器   二进制文件   工具

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号

Top