BusyBox - The Swiss Army Knife of Embedded Linux
BusyBox <function> [arguments...] # or <function> [arguments...] # if symlinked
Most BusyBox commands support the -h option to provide a terse runtime description of their behavior.
Currently defined functions include:
adjtimex, ar, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt, clear, cmp, cp, cpio, cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find, free, freeramdisk, fsck.minix, getopt, grep, gunzip, gzip, halt, head, hostid, hostname, id, ifconfig, init, insmod, kill, killall, klogd, length, ln, loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc, nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink, reboot, renice, reset, rm, rmdir, rmmod, route, rpm2cpio, sed, setkeycodes, sh, sleep, sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet, test, tftp, touch, tr, true, tty, umount, uname, uniq, unix2dos, update, uptime, usleep, uudecode, uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat, [
FILE(s)
and prints them to stdout.$ cat /proc/uptime 110716.72 17.67
-R Changes files and directories recursively.
$ ls -l /tmp/foo -r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo $ chgrp root /tmp/foo $ ls -l /tmp/foo -r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo
-R Changes files and directories recursively.
$ ls -l /tmp/foo -rw-rw-r-- 1 root root 0 Apr 12 18:25 /tmp/foo $ chmod u+x /tmp/foo $ ls -l /tmp/foo -rwxrw-r-- 1 root root 0 Apr 12 18:25 /tmp/foo* $ chmod 444 /tmp/foo $ ls -l /tmp/foo -r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo
-R Changes files and directories recursively. -h Do not dereference symbolic links.
$ ls -l /tmp/foo -r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo $ chown root /tmp/foo $ ls -l /tmp/foo -r--r--r-- 1 root andersen 0 Apr 12 18:25 /tmp/foo $ chown root.root /tmp/foo ls -l /tmp/foo -r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo
$ ls -l /bin/ls lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox $ mount /dev/hdc1 /mnt -t minix $ chroot /mnt $ ls -l /bin/ls -rwxr-xr-x 1 root root 40816 Feb 5 07:45 /bin/ls*
SOURCE(s)
to
DIRECTORY.-a Same as -dpR -d Preserves links -p Preserves file attributes if possible -f force (implied; ignored) - always set -R Copies directories recursively
-b LIST Output only bytes from LIST -c LIST Output only characters from LIST -d CHAR Use CHAR instead of tab as the field delimiter -s Output only the lines containing delimiter -f N Print only these fields -n Ignored
$ echo "Hello world" | cut -f 1 -d ' ' Hello $ echo "Hello world" | cut -f 2 -d ' ' world
-R Outputs RFC-822 compliant date string -d STRING display time described by STRING, not `now' -s Sets time described by STRING -u Prints or sets Coordinated Universal Time
$ date Wed Apr 12 18:52:41 MDT 2000
dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] |
|
[seek=N] [conv=notrunc|noerror|sync] |
if=FILE read from FILE instead of stdin of=FILE write to FILE instead of stdout bs=N read and write N bytes at a time count=N copy only N input blocks skip=N skip N input blocks seek=N skip N output blocks conv=notrunc don't truncate output file conv=noerror continue after read errors conv=sync pad blocks with zeros
$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4 4+0 records in 4+0 records out
-h print sizes in human readable format (e.g., 1K 243M 2G ) -m print sizes in megabytes -k print sizes in kilobytes(default)
$ df Filesystem 1k-blocks Used Available Use% Mounted on /dev/sda3 8690864 8553540 137324 98% / /dev/sda1 64216 36364 27852 57% /boot $ df /dev/sda3 Filesystem 1k-blocks Used Available Use% Mounted on /dev/sda3 8690864 8553540 137324 98% /
-c Clears the ring buffer's contents after printing -n LEVEL Sets console logging level -s SIZE Use a buffer of size SIZE
-l count sizes many times if hard linked -s display only a total for each argument -h print sizes in human readable format (e.g., 1K 243M 2G ) -m print sizes in megabytes -x skip directories on different filesystems -k print sizes in kilobytes(default)
$ du 16 ./CVS 12 ./kernel-patches/CVS 80 ./kernel-patches 12 ./tests/CVS 36 ./tests 12 ./scripts/CVS 16 ./scripts 12 ./docs/CVS 104 ./docs 2417 .
-n suppress trailing newline -e interpret backslash-escaped characters (i.e., \t=tab) -E disable interpretation of backslash-escaped characters
$ echo "Erik is cool" Erik is cool $ echo -e "Erik\nis\ncool" Erik is cool $ echo "Erik\nis\ncool" Erik\nis\ncool
ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2 ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0 ARG1 < ARG2 ARG1 is less than ARG2 ARG1 <= ARG2 ARG1 is less than or equal to ARG2 ARG1 = ARG2 ARG1 is equal to ARG2 ARG1 != ARG2 ARG1 is unequal to ARG2 ARG1 >= ARG2 ARG1 is greater than or equal to ARG2 ARG1 > ARG2 ARG1 is greater than ARG2 ARG1 + ARG2 arithmetic sum of ARG1 and ARG2 ARG1 - ARG2 arithmetic difference of ARG1 and ARG2 ARG1 * ARG2 arithmetic product of ARG1 and ARG2 ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2 ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2 STRING : REGEXP anchored pattern match of REGEXP in STRING match STRING REGEXP same as STRING : REGEXP substr STRING POS LENGTH substring of STRING, POS counted from 1 index STRING CHARS index in STRING where any CHARS is found, or 0 length STRING length of STRING quote TOKEN interpret TOKEN as a string, even if it is a keyword like `match' or an operator like `/' ( EXPRESSION ) value of EXPRESSION
$ false $ echo $? 1
$ fbset mode "1024x768-76" # D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz geometry 1024 768 1024 768 16 timings 12714 128 32 16 4 128 4 accel false rgba 5/11,6/5,5/0,0/0 endmode
-follow Dereference symbolic links. -name PATTERN File name (leading directories removed) matches PATTERN. -print Print (default and assumed). -type X Filetype matches X (where X is one of: f,d,l,b,c,...) -perm PERMS Permissions match any of (+NNN); all of (-NNN); or exactly (NNN) -mtime TIME Modified time is greater than (+N); less than (-N); or exactly (N) days -newer FILE Modified time is more recent than FILE's
$ find / -name /etc/passwd /etc/passwd
$ free total used free shared buffers Mem: 257628 248724 8904 59644 93124 Swap: 128516 8404 120112 Total: 386144 257128 129016
$ freeramdisk /dev/ram2
-l Lists all filenames -r Perform interactive repairs -a Perform automatic repairs -v verbose -s Outputs super-block information -m Activates MINIX-like "mode not cleared" warnings -f Force file system check.
-a, --alternative Allow long options starting with single - -l, --longoptions=longopts Long options to be recognized -n, --name=progname The name under which errors are reported -o, --options=optstring Short options to be recognized -q, --quiet Disable error reporting by getopt(3) -Q, --quiet-output No normal output -s, --shell=shell Set shell quoting conventions -T, --test Test for getopt(1) version -u, --unqote Do not quote the output
$ cat getopt.test #!/bin/sh GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \ -n 'example.busybox' -- "$@"` if [ $? != 0 ] ; then exit 1 ; fi eval set -- "$GETOPT" while true ; do case $1 in -a|--a-long) echo "Option a" ; shift ;; -b|--b-long) echo "Option b, argument `$2'" ; shift 2 ;; -c|--c-long) case "$2" in "") echo "Option c, no argument"; shift 2 ;; *) echo "Option c, argument `$2'" ; shift 2 ;; esac ;; --) shift ; break ;; *) echo "Internal error!" ; exit 1 ;; esac done
-H prefix output lines with filename where match was found -h suppress the prefixing filename on output -i ignore case distinctions -l list names of files that match -n print line number with output lines -q be quiet. Returns 0 if result was found, 1 otherwise -v select non-matching lines -s suppress file open/read error messages
$ grep root /etc/passwd root:x:0:0:root:/root:/bin/bash $ grep ^[rR]oo. /etc/passwd root:x:0:0:root:/root:/bin/bash
-c Write output to standard output -t Test compressed file integrity
$ ls -la /tmp/BusyBox* -rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz $ gunzip /tmp/BusyBox-0.43.tar.gz $ ls -la /tmp/BusyBox* -rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar
-c Write output to standard output instead of FILE.gz -d decompress
$ ls -la /tmp/busybox* -rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/busybox.tar $ gzip /tmp/busybox.tar $ ls -la /tmp/busybox* -rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz
-n NUM Print first NUM lines instead of first 10
$ head -n 2 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh
-s Short -i Addresses for the hostname -d DNS domain name -F, --file FILE Use the contents of FILE to specify the hostname
$ hostname sage
-l List all signal names and numbers.
$ ps | grep apache 252 root root S [apache] 263 www-data www-data S [apache] 264 www-data www-data S [apache] 265 www-data www-data S [apache] 266 www-data www-data S [apache] 267 www-data www-data S [apache] $ kill 252
-l List all signal names and numbers.
$ killall apache
-n Run as a foreground process.
$ length Hello 5
-s make symbolic links instead of hard links -f remove existing destination files -n no dereference symlinks - treat like normal file
$ ln -s BusyBox /tmp/ls $ ls -l /tmp/ls lrwxrwxrwx 1 root root 7 Apr 12 18:39 ls -> BusyBox*
-s Log to stderr as well as the system log. -t Log using the specified tag (defaults to user name). -p Enter the message with the specified priority. This may be numerical or a ``facility.level'' pair.
$ logger "hello"
-1 list files in a single column -A do not list implied . and .. -a do not hide entries starting with . -C list entries by columns -c with -l: show ctime -d list directory entries instead of contents -e list both full date and full time -F append indicator (one of */=@|) to entries -i list the i-node for each file -l use a long listing format -n list numeric UIDs and GIDs instead of names -p append indicator (one of /=@|) to entries -L list entries pointed to by symbolic links -R list subdirectories recursively -r sort the listing in reverse order -S sort the listing by file size -s list the size of each file, in blocks -T NUM assume Tabstop every NUM columns -t with -l: show modification time -u with -l: show access time -v sort the listing by version -w NUM assume the terminal is NUM columns wide -x list entries by lines instead of by columns -X sort the listing by extension -h print sizes in human readable format (e.g., 1K 243M 2G ) -k print sizes in kilobytes(default)
DIRECTORY(ies)
if they do not already exist-m set permission mode (as in chmod), not rwxrwxrwx - umask -p no error if existing, make parent directories as needed
$ mkdir /tmp/foo $ mkdir /tmp/foo /tmp/foo: File exists $ mkdir /tmp/foo/bar/baz /tmp/foo/bar/baz: No such file or directory $ mkdir -p /tmp/foo/bar/baz
-m create the pipe using the specified mode (default a=rw)
-c Check the device for bad blocks -n [14|30] Specify the maximum length of filenames -i INODES Specify the number of inodes for the filesystem -l FILENAME Read the bad blocks list from FILENAME -v Make a Minix version 2 filesystem
-m create the special file using the specified mode (default a=rw)
b: Make a block (buffered) device. c or u: Make a character (un-buffered) device. p: Make a named pipe. MAJOR and MINOR are ignored for named pipes.
$ mknod /dev/fd0 b 2 0 $ mknod -m 644 /tmp/pipe p
$ mktemp /tmp/temp.XXXXXX /tmp/temp.mWiLjM $ ls -la /tmp/temp.mWiLjM -rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM
$ modprobe cdrom
$ dmesg | more
-a: Mount all filesystems in fstab. -f: "Fake" Add entry to mount table but don't mount it. -n: Don't write a mount table entry. -o option: One of many filesystem options, listed below. -r: Mount the filesystem read-only. -t fs-type: Specify the filesystem type. -w: Mount for reading and writing (default).
async/sync: Writes are asynchronous / synchronous. atime/noatime: Enable / disable updates to inode access times. dev/nodev: Allow use of special device files / disallow them. exec/noexec: Allow use of executable files / disallow them. loop: Mounts a file via loop device. suid/nosuid: Allow set-user-id-root programs / disallow them. remount: Re-mount a mounted filesystem, changing its flags. ro/rw: Mount for read-only / read-write. bind: Use the linux 2.4.x "bind" feature.
$ mount /dev/hda3 on / type minix (rw) proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw) $ mount /dev/fd0 /mnt -t msdos -o ro $ mount /tmp/diskimage /opt -t ext2 -o loop
SOURCE(s)
to DIRECTORY.$ mv /tmp/foo /bin/bar
$ pidof init 1
-c COUNT Send only COUNT pings. -s SIZE Send SIZE data bytes in packets (default=56). -q Quiet mode, only displays output at start and when finished.
$ ping localhost PING slag (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=255 time=20.1 ms --- debian ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 20.1/20.1/20.1 ms
ARGUMENT(s)
according to FORMAT,
Where FORMAT controls the output exactly as in C printf.$ printf "Val=%d\n" 5 Val=5
$ ps PID Uid Gid State Command 1 root root S init 2 root root S [kflushd] 3 root root S [kupdate] 4 root root S [kpiod] 5 root root S [kswapd] 742 andersen andersen S [bash] 743 andersen andersen S -bash 745 root root S [getty] 2990 andersen andersen R ps
$ pwd /root
-s Set the system date and time (default). -p Print the date and time.
-i always prompt before removing each destination -f remove existing destinations, never prompt -r or -R remove the contents of directories recursively
$ rm -rf /tmp/foo
# rmdir /tmp/foo
-a Try to remove all unused kernel modules.
$ rmmod tulip
$ sleep 2 [2 second delay results]
-u suppress duplicate lines -r sort in reverse order -n sort numerics
$ echo -e "e\nf\nb\nd\nc\na" | sort a b c d e f
-m NUM Interval between MARK lines (default=20min, 0=off) -n Run as a foreground process -O FILE Use an alternate log file (default=/var/log/messages) -R HOST[:PORT] Log to IP or hostname on PORT (default PORT=514/UDP) -L Log locally and via network logging (default is network only)
$ syslogd -R masterlog:514 $ syslogd -R 192.168.1.1:601
-c N[kbm] output the last N bytes -n N[kbm] print last N lines instead of last 10 -f output data as the file grows -q never output headers giving file names -s SEC wait SEC seconds between reads with -f -v always output headers giving file names
$ tail -n 1 /etc/resolv.conf nameserver 10.0.0.1
c create x extract t list
f name of TARFILE or "-" for stdin O extract to stdout exclude file to exclude X file with names to exclude C change to directory DIR before operation v verbosely list files processed
$ zcat /tmp/tarball.tar.gz | tar -xf - $ tar -cf /tmp/tarball.tar /usr/local
$ test 1 -eq 2 $ echo $? 1 $ test 1 -eq 1 $ echo $? 0 $ [ -d /etc ] $ echo $? 0 $ [ -d /junk ] $ echo $? 1
-c Do not create any files
$ ls -l /tmp/foo /bin/ls: /tmp/foo: No such file or directory $ touch /tmp/foo $ ls -l /tmp/foo -rw-rw-r-- 1 andersen andersen 0 Apr 15 01:11 /tmp/foo
-c take complement of STRING1 -d delete input characters coded STRING1 -s squeeze multiple output characters of STRING2 into one character
$ echo "gdkkn vnqkc" | tr [a-y] [b-z] hello world
traceroute [-dnrv] [-m max_ttl] [-p port#] [-q nqueries] |
|
[-s src_addr] [-t tos] [-w wait] host [data size] |
-d set SO_DEBUG options to socket -n Print hop addresses numerically rather than symbolically -r Bypass the normal routing tables and send directly to a host -v Verbose output -m max_ttl Set the max time-to-live (max number of hops) -p port# Set the base UDP port number used in probes (default is 33434) -q nqueries Set the number of probes per ``ttl'' to nqueries (default is 3) -s src_addr Use the following IP address as the source address -t tos Set the type-of-service in probe packets to the following value (default 0) -w wait Set the time (in seconds) to wait for a response to a probe (default 3 sec.).
$ true $ echo $? 0
-s print nothing, only return an exit status
$ tty /dev/tty2
-a Unmount all file systems in /etc/mtab -n Don't erase /etc/mtab entries -r Try to remount devices as read-only if mount is busy -f Force umount (i.e., unreachable NFS server) -l Do not free loop device (if a loop device has been used)
$ umount /dev/hdc1
-a print all information -m the machine (hardware) type -n print the machine's network node hostname -r print the operating system release -s print the operating system name -p print the host processor type -v print the operating system version
$ uname -a Linux debian 2.2.15pre13 #5 Tue Mar 14 16:03:50 MST 2000 i686 unknown
-c prefix lines by the number of occurrences -d only print duplicate lines -u only print unique lines
$ echo -e "a\na\nb\nc\nc\na" | sort | uniq a b c
-S force use of sync(2) instead of flushing -s SECS call sync this often (default 30) -f SECS flush some buffers this often (default 5)
$ uptime 1:55pm up 2:30, load average: 0.09, 0.04, 0.00
$ usleep 1000000 [pauses for 1 second]
-c print the byte counts -l print the newline counts -L print the length of the longest line -w print the word counts
$ wc /etc/passwd 31 46 1365 /etc/passwd
$ which login /bin/login
GNU Libc uses the Name Service Switch (NSS) to configure the behavior of the C library for the local environment, and to configure how it reads system data, such as passwords and group information. BusyBox has made it Policy that it will never use NSS, and will never use and libc calls that make use of NSS. This allows you to run an embedded system without the need for installing an /etc/nsswitch.conf file and without and /lib/libnss_* libraries installed.
If you are using a system that is using a remote LDAP server for authentication via GNU libc NSS, and you want to use BusyBox, then you will need to adjust the BusyBox source. Chances are though, that if you have enough space to install of that stuff on your system, then you probably want the full GNU utilities.
textutils(1), shellutils(1), etc...
Erik Andersen <andersee@debian.org> <andersen@codepoet.org>
The following people have contributed code to BusyBox whether they know it or not.
Erik Andersen <andersee@debian.org> <andersen@codepoet.org>
Tons of new stuff, major rewrite of most of the core apps, tons of new apps as noted in header files.
John Beppu <beppu@codepoet.org>
du, head, nslookup, sort, tee, uniq (so Kraai could rewrite them ;-), documentation
Edward Betts <edward@debian.org>
expr, hostid, logname, tty, wc, whoami, yes =for html <br>
Brian Candler <B.Candler@pobox.com>
tiny-ls(ls)
Randolph Chung <tausq@debian.org>
fbset, ping, hostname, and mkfifo
Dave Cinege <dcinege@psychosis.com>
more(v2), makedevs, dutmp, modularization, auto links file, various fixes, Linux Router Project maintenance
Larry Doolittle <ldoolitt@recycle.lbl.gov>
various fixes, shell rewrite
Karl M. Hegbloom <karlheg@debian.org>
cp_mv.c, the test suite, various fixes to utility.c, &c.
Sterling Huxley <sterling@europa.com>
vi (!!!)
Daniel Jacobowitz <dan@debian.org>
mktemp.c
Matt Kraai <kraai@alumni.carnegiemellon.edu>
documentation, bugfixes
John Lombardo <john@deltanet.com>
dirname, tr
Glenn McGrath <bug1@netconnect.com.au>
ar.c
Vladimir Oleynik <dzo@simtreas.ru>
cmdedit, stty-port, locale, various fixes and irreconcilable critic of everything not perfect.
Bruce Perens <bruce@pixar.com>
Original author of BusyBox. His code is still in many apps.
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
wget - Contributed by permission of Covad Communications
Pavel Roskin <proski@gnu.org>
Lots of bugs fixes and patches.
Gyepi Sam <gyepi@praxis-sw.com>
Remote logging feature for syslogd
Linus Torvalds <torvalds@transmeta.com>
mkswap, fsck.minix, mkfs.minix
Mark Whitley <markw@codepoet.org>
sed remix, bug fixes, style-guide, etc.
Charles P. Wright <cpwright@villagenet.com>
gzip, mini-netcat(nc)
Enrique Zanardi <ezanardi@ull.es>
tarcat (since removed), loadkmap, various fixes, Debian maintenance