BusyBox It's open source (GPL) project , Provide access to 400 A simple implementation of common commands .
It's easy to think that Linux Your orders are taken for granted . When you install Linux when , They are bundled with the system , And we often don't ask why they are there . Some basic commands , Such as 、 and echo, Not always a stand-alone application , It's actually built into your shell in . Other such as 、 and It's the core toolkit ( Usually GNU coreutils
) Part of . But in the open source world , There are always alternatives , The most interesting of all is .
Linux Medium BusyBox brief introduction
BusyBox It's open source (GPL) project , Provide access to 400 A simple implementation of common commands , Include ls
、mv
、ln
、mkdir
、more
、ps
、gzip
、bzip2
、tar
and grep
. It also includes programming languages awk
、 stream editor sed
、 File system checking tool fsck
、rpm
and dpkg
Package manager , Of course, there is also a convenient way to access all these commands shell(sh
). In short , It contains all POSIX Basic commands required by the system , To perform common system maintenance tasks and many user and administrative tasks .
in fact , It even contains a init
command , It can be used as PID 1 start-up , As the parent process of all other system services . let me put it another way ,BusyBox It can be used as 、OpenRC、sinit、init And other alternatives to initialization systems .
BusyBox A very small . As an executable , It's less than 1MB, So it's in 、 and The field is very popular , Because the storage space of these scenes is very valuable . In the world of container and cloud computing , It serves as a streamlined Linux The basic image of container image is also very popular .
minimalism
BusyBox Part of its charm lies in its minimalism . All its commands are compiled into a binary file (busybox
), Its manual only 81 page ( According to my pair man
Deliver to pr
Calculation of pipeline ), But it covers nearly 400 Bar command .
As an example of comparison , This is a “ original edition ” Of useradd —help
Output :
-b, --base-dir BASE_DIR base directory for home
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change the default config
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity
-g, --gid GROUP name or ID of the primary group
-G, --groups GROUPS list of supplementary groups
-h, --help display this help message and exit
-k, --skel SKEL_DIR alternative skeleton dir
-K, --key KEY=VALUE override /etc/login.defs
-l, --no-log-init do not add the user to the lastlog
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the user's name
-o, --non-unique allow users with non-unique UIDs
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as a user
And this is the same command BusyBox edition :
-h DIR Home directory
-g GECOS GECOS field
-s SHELL Login shell
-G GRP Group
-S Create a system user
-D Don't assign a password
-H Don't create home directory
-u UID User id
-k SKEL Skeleton directory (/etc/skel)
Is this difference a feature or a limitation , It depends on whether you like your command to have 20 One option is still 10 An option . For some users and some use cases ,BusyBox Minimalism is just what you need . For others , It's a good minimization environment , It can be used as a backup tool , Or as a basis for installing more powerful tools , such as 、、GNU wait .
install BusyBox
stay Linux On , You can use your package manager to install BusyBox. for example , stay Fedora And similar distributions :
$ sudo dnf install busybox
stay Debian And its derivatives :
$ sudo apt install busybox
stay MacOS On , have access to or . stay Windows On , have access to .
You can take BusyBox Set to your shell, Use chsh —shell
command , And then add BusyBox sh
The path to the application . I put BusyBox Put it in /lib64
in , But its location depends on where your distribution is installed .
$ which busybox
/lib64/busybox/busybox
$ chsh --shell /lib64/busybox/sh
use BusyBox It's more complicated to completely replace all the common commands , Because most distributions are “ Hardwired ”, Will look for specific commands in specific software packages . let me put it another way , Although it can be used technically BusyBox Of init
Replace the init
, But your package manager may refuse to let you delete the package that contains init
Software package , Lest you worry that deleting will cause the system to fail to start . Some distributions are based on BusyBox Above , So starting from a new environment may be an experience BusyBox The simplest way to the system .
try BusyBox
You don't have to try BusyBox And put your shell Permanently changed to BusyBox. You can learn from your current shell Start one in BusyBox shell.
$ busybox sh
~ $
However, your system still has non installed BusyBox Version of command , So experience BusyBox Tools for , You must send the command as a parameter to busybox
Executable file :
~ $ busybox echo $0
sh
~ $ busybox ls --help
BusyBox vX.YY.Z (2021-08-25 07:31:48 NZST) multi-call binary.
Usage: ls [-1AaCxdLHRFplinshrSXvctu] [-w WIDTH] [FILE]...
List directory contents
-1 One column output
-a Include entries that start with .
-A Like -a, but exclude . and ..
-x List by lines
[...]
In order to obtain “ complete ” Of BusyBox Experience , You can create one for each command busybox
The symbolic link . This is easy. , As long as you use Just go :
$ mkdir bbx
$ for i in $(bbx --list); do \
ln -s /path/to/busybox bbx/$i \
done
In your Of start Add this symbolic link directory , And start the BusyBox:
$ PATH=$(pwd)/bbx:$PATH bbx/sh
To use
BusyBox It's an interesting project , It is also an achievable The minimalist An example of calculation . Whether you put BusyBox As Lightweight environment , Or as The user interface , Or try a new initialization system , Even for curiosity , Let yourself re recognize those familiar and unfamiliar commands , Will be very interesting .
via:
author : Topic selection : translator : proofreading :
This paper is written by Original compilation , Honor roll out

版权声明
本文为[Linux China]所创,转载请带上原文链接,感谢
https://cdmana.com/2021/10/20211002150150610e.html