Android toybox常用工具介绍

Android toybox常用工具介绍

源码路径:external/toybox

一、支持的工具:

acpi, base64, basename, bc, blockdev, cal, cat, chcon, chgrp, chmod, chown, chroot, chrt, cksum, clear, comm, cmp, cp, cpio, cut, date, dd, devmem, df, diff, dirname, dmesg, dos2unix, du, echo, env, expand, expr, fallocate, false, file, find, flock, fmt, free, fsync, getconf, getenforce, groups, gunzip, gzip, head, hostname, hwclock, i2cdetect, i2cdump, i2cget, i2cset, iconv, id, ifconfig, inotifyd, insmod, install, ionice, iorenice, kill, killall, load_policy, ln, log, logname, losetup, ls, lsmod, lsof, lspci, lsusb, md5sum, mkdir, mkfifo, mknod, mkswap, mktemp, microcom, modinfo, modprobe, more, mount, mountpoint, mv, nc, netcat, netstat, nice, nl, nohup, nproc, nsenter, od, paste, patch, pgrep, pidof, pkill, pmap, printenv, printf, ps, pwd, readlink, realpath, renice, restorecon, rm, rmdir, rmmod, runcon, sed, sendevent, seq, setenforce, setprop, setsid, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, sleep, sort, split, start, stat, stop, strings, stty, swapoff, swapon, sync, sysctl, tac, tail, tar, taskset, tee, time, timeout, top, touch, tr, true, truncate, tty, ulimit, umount, uname, uniq, unix2dos, unlink, unshare, uptime, usleep, uudecode, uuencode, uuidgen, vmstat, watch, wc, which, whoami, xargs, xxd, yes, zcat

二、常用工具介绍(太常用的也不介绍):

1. watch:用于周期性监控文件或设备状态的变化,支持简单命令,help如下
msm8953_64:/ # watch --help
usage: watch [-teb] [-n SEC] PROG ARGS

Run PROG every -n seconds, showing output. Hit q to quit.

-n      Loop period in seconds (default 2)
-t      Don't print header
-e      Exit on error
-b      Beep on command error
-x      Exec command directly (vs "sh -c")

msm8953_64:/ #

如:watch -n 5 ps -A,间隔5S执行一次ps -A命令

2. **acpi :**监控电池状态变化
msm8953_64:/ # acpi --help
usage: acpi [-abctV]
Show status of power sources and thermal devices.
-a      Show power adapters
-b      Show batteries
-c      Show cooling device state
-t      Show temperatures
-V      Show everything
msm8953_64:/ #
3. base64:对数据进行Base64编码或解码操作
130|msm8953_64:/ # base64 --help
usage: base64 [-di] [-w COLUMNS] [FILE...]
Encode or decode in base64.
-d      Decode
-i      Ignore non-alphabetic characters
-w      Wrap output at COLUMNS (default 76 or 0 for no wrap)
msm8953_64:/ #
4. pkill:通过进程名或其他属性发送信号终止进程的命令行工具
msm8953_64:/ # pkill --help
usage: pkill [-fnovx] [-SIGNAL|-l SIGNAL] [PATTERN] [-G GID,] [-g PGRP,] [-P PPID,] [-s SID,] [-t TERM,] [-U UID,] [-u EUID,]
-l      Send SIGNAL (default SIGTERM)
-V      Verbose
-f      Check full command line for PATTERN
-G      Match real Group ID(s)
-g      Match Process Group(s) (0 is current user)
-n      Newest match only
-o      Oldest match only
-P      Match Parent Process ID(s)
-s      Match Session ID(s) (0 for current)
-t      Match Terminal(s)
-U      Match real User ID(s)
-u      Match effective User ID(s)
-v      Negate the match
-x      Match whole command (not substring)
msm8953_64:/ #
5. dmesg:查看kernel 日志
msm8953_64:/ # dmesg --help
usage: dmesg [-Cc] [-r|-t|-T] [-n LEVEL] [-s SIZE] [-w]
Print or control the kernel ring buffer.
-C      Clear ring buffer without printing
-c      Clear ring buffer after printing
-n      Set kernel logging LEVEL (1-9)
-r      Raw output (with <level markers>)
-S      Use syslog(2) rather than /dev/kmsg
-s      Show the last SIZE many bytes
-T      Human readable timestamps
-t      Don't print timestamps
-w      Keep waiting for more output (aka --follow)
msm8953_64:/ #
6. hostname:系统中用于‌查看或设置主机名(hostname)‌的命令行工具
msm8953_64:/ # hostname --help
usage: hostname [-bdsf] [-F FILENAME] [newname]
Get/set the current hostname.
-b      Set hostname to 'localhost' if otherwise unset
-d      Show DNS domain name (no host)
-f      Show fully-qualified name (host+domain, FQDN)
-F      Set hostname to contents of FILENAME
-s      Show short host name (no domain)
msm8953_64:
7. i2cdetect:系统中用于‌检测 I2C 总线设备‌的命令行工具
msm8953_64:/ # i2cdetect --help
usage: i2cdetect [-ary] BUS [FIRST LAST]
usage: i2cdetect -F BUS
usage: i2cdetect -l
Detect i2c devices.
-a      All addresses (0x00-0x7f rather than 0x03-0x77)
-F      Show functionality
-l      List all buses #列出所有设备
-r      Probe with SMBus Read Byte
-y      Answer "yes" to confirmation prompts (for script use)
msm8953_64:/ # i2cdetect -l
i2c-2   i2c             MSM-I2C-v2-adapter                      I2C Adapter
msm8953_64:/ # i2cdetect -y 2  
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- UU
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- UU -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
msm8953_64:/ #

UU 表示该地址存在设备‌

8. i2cdump:读取 I2C 设备寄存器内容的命令行工具
1|msm8953_64:/ # i2cdump --help
usage: i2cdump [-fy] BUS CHIP
Dump i2c registers.
-f      Force access to busy devices
-y      Answer "yes" to confirmation prompts (for script use)
msm8953_64:

如:i2cdump -y 2 0x0F

9. i2cget:读取 I2C 设备指定寄存器数据‌的命令行工具
msm8953_64:/ # i2cget --help
usage: i2cget [-fy] BUS CHIP ADDR
Read an i2c register.
-f      Force access to busy devices
-y      Answer "yes" to confirmation prompts (for script use)
msm8953_64:

如:i2cget -y 2 0x0F 0x02

10. lsmod:系统中用于‌列出当前加载的内核模块‌的命令行工具
msm8953_64:/ # lsmod --help
usage: lsmod
Display the currently loaded modules, their sizes and their dependencies.
msm8953_64:lsmod
Module                  Size  Used by
machine_ext_dlkm      122880  0
machine_dlkm           86016  0
wcd9335_dlkm          364544  1 machine_ext_dlkm
cpe_lsm_dlkm           49152  0
wcd_cpe_dlkm           94208  2 wcd9335_dlkm,cpe_lsm_dlkm
analog_cdc_dlkm       585728  2 machine_dlkm
digital_cdc_dlkm       77824  2 machine_dlkm
stub_dlkm              16384  1
mbhc_dlkm              49152  2 wcd9335_dlkm,analog_cdc_dlkm
wsa881x_analog_dlkm    40960  1 machine_dlkm
wsa881x_dlkm           49152  2 machine_ext_dlkm,wsa881x_analog_dlkm
wcd9xxx_dlkm           69632  2 wcd9335_dlkm,analog_cdc_dlkm
wcd_core_dlkm         143360  8 machine_ext_dlkm,machine_dlkm,wcd9335_dlkm,wcd_cpe_dlkm,mbhc_dlkm,wsa881x_analog_dlkm,wsa881x_dlkm,wcd9xxx_dlkm
hdmi_dlkm              16384  0
swr_ctrl_dlkm          32768  1 wcd9335_dlkm
swr_dlkm               28672  2 wsa881x_dlkm,swr_ctrl_dlkm
pinctrl_wcd_dlkm       16384  0
native_dlkm           184320  0
platform_dlkm        1798144  33 native_dlkm
usf_dlkm               65536  0
q6_dlkm               933888  11 machine_ext_dlkm,machine_dlkm,wcd_cpe_dlkm,analog_cdc_dlkm,digital_cdc_dlkm,wcd9xxx_dlkm,native_dlkm,platform_dlkm,usf_dlkm
adsp_loader_dlkm       16384  0
apr_dlkm              266240  7 wcd9335_dlkm,analog_cdc_dlkm,digital_cdc_dlkm,platform_dlkm,usf_dlkm,q6_dlkm,adsp_loader_dlkm
q6_notifier_dlkm       16384  2 analog_cdc_dlkm,apr_dlkm
11. whoami:显示当前执行用户的用户名
msm8953_64:/ # whoami
root
msm8953_64:
12. iconv:字符编码转换
msm8953_64:/ # iconv --help
usage: iconv [-f FROM] [-t TO] [FILE...]
Convert character encoding of files.
-c      Omit invalid chars
-f      Convert from (default utf8)
-t      Convert to   (default utf8)
msm8953_64:
13. **hwclock:**管理硬件时钟
msm8953_64:/ # hwclock --help
usage: hwclock [-rswtluf]
Get/set the hardware clock.
-f FILE Use specified device file instead of /dev/rtc (--rtc)
-l      Hardware clock uses localtime (--localtime)
-r      Show hardware clock time (--show)
-s      Set system time from hardware clock (--hctosys)
-t      Set the system time based on the current timezone (--systz)
-u      Hardware clock uses UTC (--utc)
-w      Set hardware clock from system time (--systohc)
msm8953_64:/ # hwclock -r
Tue Jan 20 23:13:59 1970  0.000000 seconds
msm8953_64:
14. sysctl:动态配置内核运行时参数(kernel 常用)
1|msm8953_64:/ # sysctl --help
usage: sysctl [-aAeNnqw] [-p [FILE] | KEY[=VALUE]...]
Read/write system control data (under /proc/sys).
-a,A    Show all values 
-e      Don't warn about unknown keys
-N      Don't print key values
-n      Don't print key names
-p      Read values from FILE (default /etc/sysctl.conf)
-q      Don't show value after write
-w      Only write values (object to reading)
msm8953_64:
15. uptime:快速查看系统运行状态的核心工具
msm8953_64:/ # uptime --help
usage: uptime [-ps]
Tell the current time, how long the system has been running, the number
of users, and the system load averages for the past 1, 5 and 15 minutes.
-p      Pretty (human readable) uptime #简洁显示运行时间
-s      Since when has the system been up? #显示系统启动的具体时间戳
msm8953_64:

如下:

msm8953_64:/ # uptime -p
up 0 weeks, 0 days, 3 hours, 19 minutes
msm8953_64:/ # uptime -s
2025-07-23 03:29:03
msm8953_64:/ # uptime
 06:49:09 up  3:20,  0 users,  load average: 8.73, 8.62, 8.62 
 #当前时间:06:49:09
 #up  3:20:已经运行3小时20分钟
 #load average: 8.73, 8.62, 8.62 :过去 1/5/15 分钟CPU的平均负载值
msm8953_64:/ #

16. vmstat:系统中用于‌实时监控系统资源状态的核心工具,通过读取 /proc 虚拟文件系统提供内存、CPU、I/O 等关键指标的动态统计‌
msm8953_64:/ # vmstat --help
usage: vmstat [-n] [DELAY [COUNT]]
Print virtual memory statistics, repeating each DELAY seconds, COUNT times.
(With no DELAY, prints one line. With no COUNT, repeats until killed.)
Show processes running and blocked, kilobytes swapped, free, buffered, and
cached, kilobytes swapped in and out per second, file disk blocks input and
output per second, interrupts and context switches per second, percent
of CPU time spent running user code, system code, idle, and awaiting I/O.
First line is since system started, later lines are since last line.
-n      Display the header only once
msm8953_64:
msm8953_64:/ # vmstat -n 
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
17  0  83268  32076  45524 625956    1    3    31   332    0 3689 21 15 64  0
msm8953_64:/ # vmstat -n 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 8  0  83268  22464  45720 624456    1    3    31   333    0 3689 21 15 64  0
 2  0  83268  33628  45728 624188    0    0     0    16    0 18754 22 16 62 0
 4  0  83268  23684  45732 627652    0    0     0  4341    0 18625 22 14 64 0
 9  0  83268  22888  45740 623524    0    0     0    18    0 18697 22 16 62 0
 7  0  83268  28724  45740 626932    0    0     0     0    0 18916 22 16 62 0
msm8953_64:/ #
#swpd:虚拟内存 free:空闲内存 buff:缓冲区 cache:缓存 
17. renice:动态调整运行中进程优先级
renice --help
usage: renice [-gpu] -n increment ID ...
msm8953_64:/ #
-n:指定新的 nice 值(必填-20~19)
-p:针对特定 PID 的进程
-u:调整某用户的所有进
-g:调整某进程组的所有成员
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值