linux busybox怎么使用

63次阅读
没有评论

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

这篇文章主要介绍了 linux busybox 怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇 linux busybox 怎么使用文章都会有所收获,下面我们一起来看看吧。

busybox 是一款开发 Linux 系统下软件的开发工具,是一个集成了三百多个最常用 Linux 命令和工具的软件。简单的说 BusyBox 就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令,也包含了 Linux 系统的自带的 shell。BusyBox 是 GNU Coreutils 的绝佳替代品,特别是在操作系统的小尺寸很重要的情况下。

BusyBox 现在越来越流行,特别是在 Docker 用户中,许多 Docker 镜像使用 BusyBox 为您提供最小镜像。

如果您认为 Linux 命令是理所当然的,这可能会让许多用户感到特别困惑,您认为 ls、mv 和其他此类命令是 Linux 的一部分,而事实是这些命令是 GNU Coreutils 软件包的一部分,并且大多数 Linux 发行版都预装了它。

GNU Coreutils 几乎是各种 UNIX/Linux 命令的事实上的提供者,几乎是因为总是有替代品,而 BusyBox 就是 GNU Coreutils 的替代品之一。

什么是 BusyBox?

busybox 是一款开发 Linux 系统下软件的开发工具。

BusyBox 是一个开源项目,它提供了大约 400 个常见 UNIX/Linux 命令的精简实现。

BusyBox 是一个集成了三百多个最常用 Linux 命令和工具的软件。BusyBox 包含了一些简单的工具,例如 ls、cat 和 echo 等等,还包含了一些更大、更复杂的工具,例 grep、find、mount 以及 telnet。有些人将 BusyBox 称为 Linux 工具里的瑞士军刀。简单的说 BusyBox 就好像是个大工具箱,它集成压缩了 Linux 的许多工具和命令,也包含了 Linux 系统的自带的 shell。

BusyBox 实现删除了不常见的、很少使用的命令选项,一切都小于 1 MB,这个最小的图像是它在嵌入式系统和物联网领域以及云计算世界中流行的原因。

不要看它的大小,BusyBox 像经典编辑器一样具有 sed 和 awk 的范围(再次精简版),它也包含自己的 shell,它甚至包含一个可以作为 PID 1 启动的 init 命令,这意味着 BusyBox 可以配置为 Systemd、OpenRC 等的替代品。

BusyBox 是 GNU Coreutils 的绝佳替代品,特别是在操作系统的小尺寸很重要的情况下。

BusyBox 为您提供流行的 Linux 命令,如 mv、mkdir、ls 等,但它仅包含这些命令的常用选项。这种极简主义是 BusyBox 的 USP。

您没有使用 BusyBox 获得完整的 Linux 命令选项是一个问题吗?

这取决于你的需要,真的,大多数人永远不需要命令的所有选项。一些 Linux 命令有超过 50 个选项,我敢打赌,你甚至从未使用过单个 Linux 命令的所有选项。

BusyBox 减少了很少使用的选项,例如,ls 命令具有选项 G,它从长列表输出 (ls -l) 中删除组名。

现在,我认为你从来不需要这个选项,这就是为什么它在 BusyBox 的 ls 实现中不存在的原因,如果您确实需要一个不包含组名的输出,您所要做的就是为此目的使用 cut 或 awk 命令。

再举一个例子。这是来自 GNU Coreutils 的 mv 命令的帮助页面:

Usage: mv [OPTION]... [-T] SOURCE DEST
 or: mv [OPTION]... SOURCE... DIRECTORY
 or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
 --backup[=CONTROL] make a backup of each existing destination file
 -b like --backup but does not accept an argument
 -f, --force do not prompt before overwriting
 -i, --interactive prompt before overwrite
 -n, --no-clobber do not overwrite an existing file
If you specify more than one of -i, -f, -n, only the final one takes effect.
 --strip-trailing-slashes remove any trailing slashes from each SOURCE
 argument
 -S, --suffix=SUFFIX override the usual backup suffix
 -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
 -T, --no-target-directory treat DEST as a normal file
 -u, --update move only when the SOURCE file is newer
 than the destination file or when the
 destination file is missing
 -v, --verbose explain what is being done
 -Z, --context set SELinux security context of destination
 file to default type
 --help display this help and exit
 --version output version information and exit

现在,这里是 BusyBox 的 mv 命令帮助页面:

Usage: mv [-fin] SOURCE DEST
or: mv [-fin] SOURCE... DIRECTORY
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY
 -f Don t prompt before overwriting
 -i Interactive, prompt before overwrite
 -n Don t overwrite an existing file

看到不同?

如何获得 BusyBox?

您可以通过多种方式获得 BusyBox。

如果您只是想在当前的 Linux 发行版上体验 BusyBox,您可以使用发行版的包管理器(如 Apt 或 DNF 或 Yum)安装它。

在 Ubuntu 上,您可以使用以下命令安装 BusyBox:

sudo apt install busybox

之后,如果要运行 BusyBox 版本的命令,则必须在其前面添加 busybox。

busybox cat sample.txt

如果 BusyBox 未实现命令,则会引发“找不到小程序”的错误。

abhishek@LHB:~$ busybox xyz
xyz: applet not found

或者,您可以下载 BusyBox 的 Docker 镜像并在运行的容器中体验它。

请确保您已安装 Docker,拉取官方 docker 镜像:

docker pull busybox

从镜像运行一个容器并进入 BusyBox shell:

docker run -it --rm busybox

您在此处运行的每个 Linux 命令都来自 BusyBox。您不需要明确指定它。

关于“linux busybox 怎么使用”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“linux busybox 怎么使用”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-13发表,共计3334字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)