busybox是一款开发linux系统下软件的开发工具,是一个集成了三百多个最常用linux命令和工具的软件。简单的说busybox就好像是个大工具箱,它集成压缩了linux的许多工具和命令,也包含了 linux系统的自带的shell。busybox是gnu coreutils的绝佳替代品,特别是在操作系统的小尺寸很重要的情况下。
本教程操作环境:linux7.3系统、dell g3电脑。
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 fileif 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 destor: mv [-fin] source... directoryrename 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 xyzxyz: applet not found
或者,您可以下载busybox 的 docker 镜像并在运行的容器中体验它。
请确保您已安装 docker,拉取官方docker镜像:
docker pull busybox
从镜像运行一个容器并进入 busybox shell:
docker run -it --rm busybox
您在此处运行的每个 linux 命令都来自 busybox。您不需要明确指定它。
总之,您不需要在常规 linux 系统上使用 busybox,您已经拥有来自 gnu coreutils 的完整版本的 linux 命令。无需安装精简版。
但是 busybox 在特殊领域有其用途,例如为嵌入式或物联网设备配置最小的 linux 操作系统时。当您希望保持 docker 映像的大小较小时也是如此。
相关推荐:《linux视频教程》
以上就是linux busybox是什么的详细内容。
