共計 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 行業資訊頻道。