Android Debug Bridge(ADB)常用命令大全

引言

Android Debug Bridge(ADB)是一套功能强大的命令行工具,它为Android开发者和高级用户提供了与Android设备通信的能力。无论是进行应用开发、测试还是执行日常设备管理任务,ADB都是不可或缺的工具。

设备管理

  • adb devices - 列出连接的设备
  • adb shell - 进入设备的shell环境
  • adb reboot - 重启设备
  • adb reboot recovery - 重启到recovery模式
  • adb reboot bootloader - 重启到bootloader模式
  • adb root - 重启adbd以获得root权限
  • adb remount - 重新挂载系统分区以允许写入
  • adb start-server - 启动ADB服务
  • adb kill-server - 停止ADB服务
  • adb get-state - 获取设备的当前状态
  • adb get-serialno - 获取设备的序列号
  • adb connect <host>:<port> - 连接到指定的设备
  • adb disconnect <device> - 断开与设备的连接
  • adb shell top - 显示设备当前的进程信息
  • adb shell ps - 显示设备的进程列表
  • adb shell pm list packages - 列出设备上安装的所有应用包
  • adb shell getprop ro.product.model - 查看手机型号
  • adb shell dumpsys battery - 查看电池状况
  • adb shell wm size - 查看分辨率
  • adb shell getprop ro.build.version.release - 查看 Android 系统版本
  • adb shell cat /proc/cpuinfo - 查看CPU信息
  • adb shell cat /proc/meminfo - 查看内存信息
  • adb shell cat /system/build.prop - 查看所有属性

应用管理

  • adb install <apk> - 安装指定路径的APK文件到设备
  • adb uninstall <package> - 卸载设备上指定的应用包
  • adb uninstall -k <package> - 卸载应用但保留其数据和缓存目录
  • adb shell pm list packages - 列出设备上所有安装的应用包
  • adb shell pm list packages -3 - 只列出设备上第三方应用的包名
  • adb shell pm list packages -s - 只列出系统应用的包名
  • adb shell pm list packages -d - 列出已禁用的应用包名
  • adb shell pm list applications - 列出所有应用程序的信息
  • adb shell pm list features - 列出所有已安装应用的特性
  • adb shell pm get-install-location - 获取应用的安装位置
  • adb shell pm set-install-location <location> - 设置应用的安装位置,例如internalOnlypreferExternal
  • adb shell am force-stop <package> - 强制停止指定应用的所有后台进程
  • adb shell pm dump <package> - 打印出指定应用包的详细信息
  • adb shell pm path <package> - 打印出指定应用包的APK文件路径

文件操作

  • adb pull <remote> <local> - 从设备中指定的<remote>路径拉取文件到本地的<local>路径
  • adb push <local> <remote> - 将本地的<local>文件或目录推送到设备的<remote>路径
  • adb sync - 同步设备和PC端的文件系统
  • adb sync <volume> - 同步指定的<volume>卷,如systemdata
  • adb pull -a - 自动确认拉取所有文件,不进行任何提示
  • adb push -a - 自动确认推送所有文件,不进行任何提示
  • adb shell ls <path> - 列出设备上<path>目录的文件和文件夹
  • adb shell mkdir <path> - 在设备上创建名为<path>的新目录
  • adb shell rmdir <path> - 删除设备上名为<path>的空目录
  • adb shell rm <file> - 删除设备上名为<file>的文件
  • adb shell mv <src> <dest> - 在设备上移动或重命名文件,从<src><dest>
  • adb shell cp <src> <dest> - 在设备上复制文件,从<src><dest>
  • adb shell cat <file> - 显示设备上<file>文件的内容
  • adb shell echo <text> > <file> - 将<text>文本写入设备上的<file>文件,覆盖原有内容
  • adb shell chmod <mode> <file> - 更改设备上<file>文件的权限为<mode>模式
  • adb shell chown <user>:<group> <file> - 更改设备上<file>文件的所有者为<user>和组为<group>
  • adb shell find <path> <expression> - 在设备上<path>目录中查找匹配<expression>的文件
  • adb shell grep <pattern> <file> - 在设备上<file>文件中搜索匹配<pattern>的文本
  • adb shell tar -xvf <file> - 在设备上解压<file>.tar文件
  • adb shell tar -cvf <file> <path> - 在设备上将<path>目录或文件压缩成<file>.tar文件
  • adb shell unzip <file> - 在设备上解压<file>.zip文件
  • adb shell gzip <file> - 在设备上使用gzip压缩<file>文件
  • adb shell gunzip <file> - 在设备上使用gzip解压缩<file>.gz文件
  • adb shell dd if=<file> of=<device> - 使用dd命令在设备上将文件<file>复制到设备的特殊设备<device>,如/dev/null
  • adb shell dd if=<device> of=<file> - 使用dd命令在设备上从特殊设备<device>复制到文件<file>,如从/dev/zero
  • adb shell mount - 显示设备上所有挂载的文件系统信息
  • adb shell mount -t <type> <device> <mountpoint> - 在设备上挂载文件系统,指定类型<type>,设备<device>和挂载点<mountpoint>
  • adb shell umount <mountpoint> - 卸载设备上<mountpoint>的文件系统
  • adb shell df - 显示设备上每个文件系统的磁盘空间使用情况
  • adb shell su - 切换到设备的超级用户(root)环境

安全和权限

  • adb root - 重启adbd daemon以获得root权限
  • adb remount - 重新挂载/system分区为可写模式
  • adb shell pm grant <package> <permission> - 授予应用特定权限
  • adb shell pm revoke <package> <permission> - 撤销应用的特定权限
  • adb shell pm list permissions - 列出所有可用的权限
  • adb shell getenforce - 查看当前SELinux的执行模式
  • adb shell setenforce <mode> - 设置SELinux的执行模式
  • adb shell pm get-package <package> - 查看应用的签名信息
  • adb shell chmod <mode> <file> - 更改文件或目录的访问权限
  • adb shell chown <user>:<group> <file> - 更改文件或目录的所有者和组
  • adb logcat - 查看包含安全相关信息的日志
  • adb shell settings get <setting> - 获取系统安全相关的配置
  • adb shell settings put <setting> <value> - 设置系统安全相关的配置

日志管理

  • adb logcat - 显示设备的实时日志输出
  • adb logcat -c - 清除当前的日志缓冲区
  • adb logcat -d - 转储并清除设备上的日志
  • adb logcat -f <file> - 将日志输出保存到指定的文件
  • adb logcat -v <format> - 设置日志的输出格式,如briefprocesstagthread
  • adb logcat <filter> - 根据指定的过滤器显示日志,如按进程名、标签或优先级过滤
  • adb logcat -s <tag1>:<priority> <tag2>:<priority> - 指定显示日志的标签和优先级
  • adb logcat | grep <pattern> - 使用管道和grep命令过滤日志输出
  • adb shell dmesg - 显示内核日志信息
  • adb shell logcat -v long - 显示更详细的日志信息,包括时间戳等
  • adb shell logcat -v time - 显示带有时间戳的日志信息
  • adb shell logcat -r <size> - 从日志缓冲区中读取指定大小的日志数据

模拟按键输入

  • adb shell input keyevent <keycode> - 模拟一个按键事件,<keycode>是按键的唯一标识符。
  • adb shell input text <text> - 模拟文本输入,将<text>字符串输入到当前的输入字段。
  • adb shell input tap <x> <y> - 在屏幕上的坐标(<x>, <y>)模拟一个触摸点击事件。
  • adb shell input swipe <x1> <y1> <x2> <y2> <time> - 模拟一个从点(<x1>, <y1>)到点(<x2>, <y2>)的滑动操作,<time>是滑动持续的时间(毫秒)。
  • adb shell input press <keycode> - 模拟按下一个按键。
  • adb shell input release <keycode> - 模拟释放一个按键。

网络管理

  • adb shell cat /data/misc/wifi/*.conf - 查看wifi密码
  • adb shell netcfg - 显示设备的网络配置信息。
  • adb shell ifconfig - 显示设备的网络接口配置,类似于Linux系统的ifconfig命令。
  • adb shell ip addr - 显示设备的网络接口的IP地址,类似于Linux系统的ip addr命令。
  • adb shell ip link - 显示设备的网络接口链接状态,类似于Linux系统的ip link命令。
  • adb shell ip route - 显示设备的路由表,类似于Linux系统的ip route命令。
  • adb shell ip neigh - 显示设备的邻居表,类似于Linux系统的ip neigh命令。
  • adb shell setprop net.dns1 <dns> - 设置设备的主要DNS服务器地址。
  • adb shell setprop net.dns2 <dns> - 设置设备的次要DNS服务器地址。
  • adb shell getprop net.dns1 - 获取设备的主要DNS服务器地址。
  • adb shell getprop net.dns2 - 获取设备的次要DNS服务器地址。
  • adb shell am startservice -n <service_component> - 启动网络相关的服务,例如<service_component>可能是com.android.server.NetworkTimeUpdateService
  • adb shell am broadcast -a android.intent.action.NETWORK_SCORCHED - 发送一个广播,请求网络状态改变。
  • adb shell settings put global airplane_mode_on - 启用飞行模式。
  • adb shell settings put global airplane_mode_off - 禁用飞行模式。
  • adb shell settings get global airplane_mode - 获取当前是否启用了飞行模式。

其他

  • adb exec-out screencap -p > 1.png - 屏幕截图
  • adb pull /sdcard/1.png - png 文件导出到电脑
  • adb shell screenrecord /sdcard/2.mp4 - 录制屏幕以 mp4 格式保存到 /sdcard
  • adb pull /sdcard/2.mp4 - 导出到电脑

结语

ADB命令是Android开发和设备管理的强大工具。掌握这些基本命令,可以帮助你更高效地进行开发和调试工作。

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

blues_C

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值