adb命令

1.adb devices

查看当前的安卓设备,包含手机和模拟器,返回设备序列号和状态
offline,下线,重新插拔或重新打开USB调试
device,正常
unauthorized,未授权

adb verison #查看adb版本
adb help #获取adb帮助信息

2.adb forward转发端口,没用过

3.adb kill-server /adb start-server 重启adb服务

4.adb connect

#指定端口号
adb tcpip 15556
#查看手机IP地址,通过命令行查看或通过wlan查看IP地址
adb shell ifconfig wlan0
#连接手机
adb connect 172.16.1.164:15556
#断开连接
adb disconnect 172.16.1.164:15556
## 5.adb install ```#shell #常用: adb install test.apk #直接安装应用,确定设备中未安装,否则提示应用已存在 adb install -r test.apk # 覆盖安装 #不常用: adb install -l test.apk #向前锁定应用 adb install -t test.apk #允许安装测试包 adb install -s test.apk #安装到sd卡 adb install -d test.apk #允许降级安装 adb install -p test.apk #部分安装应用 adb install -g test.apk #为应用程序授予所有运行时的权限,限原生手机 ``` 问题:[ INSTALL_FAILED_UID_CHANGED ]:卸载不完全,有残留文件,导致无法安装 方法:对于已经root过的测试机,可以进入/data/data中,把对应的包名文件夹删了,就可以正常安装了。 非root机型:重置手机 [更多问题https://www.jianshu.com/p/9025b11b6b3c或自行百度](https://www.jianshu.com/p/9025b11b6b3c)

6.adb uninstall

adb uninstall packageName
adb uninstall -k packageName #卸载应用保留数据和缓存

7.adb shell pm list packages 列出所有应用列表

adb shell pm list packages -f     #See their associated file. 查看引用列表并列出关联文件
```#shell adb shell pm list packages -d #Filter to only show disabled packages. 只显示禁用的应用 ``` ```#shell adb shell pm list packages -e # Filter to only show enabled packages.只显示可用的应用 adb shell pm list packages -s #Filter to only show system packages.只显示系统应用 adb shell pm list packages -3 #Filter to only show third party packages.只显示第3方应用 adb shell pm list packages -i #See the installer for the packages.显示应用及安装者 ``` ```#shell adb shell pm list packages -u #Also include uninstalled packages.包含已经卸载的应用 adb shell pm list packages --user #The user space to query.根据用户id查询用户的空间的所有包,USER_ID代表当前连接设备的顺序,从零开始。 ```

7.adb shell pm path

Print the path to the APK of the given . 打印指定包名的apk路径

8.adb shell pm clear packageName 清除数据,重置应用

9.adb pull

adb pull /sdcard/test.txt 复制文件到当前目录
adb pull /sdcard/test.txt ~/user/Desktop 复制文件到指定目录

10.adb push

adb push test.txt /sdcard    复制当前目录指定文件test.txt到指定目录
adb push ~/user/Desktop/text.txt /sdcard 复制指定目录下的指定文件到指定目录

11.adb shell

11.1 ls显示当前目录下的文件

-a 显示所有文件及目录 (ls内定将文件名或目录名称开头为"."的视为隐藏档,不会列出)
-i 显示文件索引号
-s print size of each file, in blocks显示文件和目录的大小,以区块为单位
-n list numeric UIDs and GIDs列出用户id和组的id
-l 除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出
-r 将文件以相反次序显示(原定依英文字母次序)
-t 将文件依建立时间之先后次序列出
-A 同 -a ,但不列出 "." (目前目录) 及 ".." (父目录)
-F 在列出的文件名称后加一符号;例如可执行档则加 "*", 目录则加 "/"
-R 若目录下有文件,则以下之文件亦皆依序列出

11.2 cd

cd /system
cd ..

11.3 mkdir

mkdir /tmp
mkdir -m 777 /tmp 目录权限
mkdir -p /tmp/sub1/sub2 新建tmp/sub1/sub2,如果某个目录不存在,就创建

11.4 rm

rm -f 删除文件
rm -r 删除目录下的所有文件
rm -d 删除目录,即使目录不是非空
rm -i 删除前提示

11.5 touch

创建文件 touch test.txt

11.6 pwd 查看当前路径

11.7 cp 复制文件

cp 源文件 目的地址

复制test.txt并将文件命名为demo.txt
cp /sdcard/test.txt /sdcard/demo.txt 
cp /sdcard/test.txt /sdcard/Download/

11.8 mv

不同目录下移动文件:mv 源文件 目的地址

#移动文件并重命名
mv /sdcard/test.txt /sdcatd/Download/demo.txt 
#移动文件
mv /sdcard/test.txt /sdcard/Download/ 

同一目录下重命名文件:mv 源文件 name 改名

mv /sdcard/test.txt /sdcard/demo.txt

11.9 netstat

显示网络状态,利用该指令可让你得知整个Linux系统的网络情况

11.10 ping

ping命令用于检测主机。执行ping命令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息。
ping [-dfnqrRv] [-c 完成次数] [-i 间隔秒数] [-I 大写i网络界面] [-l 小写l前置载入]
[-p 范本样式] [-S 数据包大小] [-t 存活数值] [-w deadline时间停止] [-W 超时时间] [hop1 ...] destination

  • -d 使用Socket的SO_DEBUG功能。
  • -c<完成次数> 设置完成要求回应的次数。
  • -f 极限检测。
  • -i<间隔秒数> 指定收发信息的间隔时间。
  • -I<网络界面> 使用指定的网络接口送出数据包。
  • -l<前置载入> 设置在送出要求信息之前,先行发出的数据包。
  • -n 只输出数值。
  • -p<范本样式> 设置填满数据包的范本样式。
  • -q 不显示指令执行过程,开头和结尾的相关信息除外。
  • -r 忽略普通的Routing Table,直接将数据包送到远端主机上。
  • -R 记录路由过程。
  • -s<数据包大小> 设置数据包的大小。
  • -t<存活数值> 设置存活数值TTL的大小。
  • -v 详细显示指令的执行过程。
#检测是否于主机连通
ping www.baidu.com
#指定接收包的次数
ping -c 4 www.baidu.com
#多参数使用,间隔3秒,发送5次,包的大小限制为1024,TTL值设置为255
ping -c 5 -i 3 -s 1024 -t 255 g.cn 

11.11 查看ip地址

ip命令和ifconfig类似,但前者功能更强大,并只在取代后者。ifconfig是net-tools中已被废弃使用的一个命令,多年没有维护了。

ip addr show wlan0
ifconfig wlan0

12 adb logcat

12.1 adb logcat 直接打印日志

### 12.2 adb logcat [:priority] 打印指定级别的日志 * 日志级别有Verbose、Debug、Info、Warn、Error、Fatal(致命的)、Silent(一切都不打印),用首字母表示

adb logcat *:V 只显示verbose级别的日志
adb logcat *😄 只显示debug级别的日志
adb logcat *:I 只显示Info级别的日志
adb logcat *:W 只显示Warning级别的日志
adb logcat *:E 只显示Error级别的日志
adb logcat *:F 只显示Fatal级别的日志
adb logcat *:S 不打印任何内容

12.3 adb logcat -b , --buffer= 缓冲

Request alternate ring buffer, 'main','system', 'radio', 'events', 'crash', 'default' or 'all'. Multiple -b parameters or comma separated list of buffers are allowed. Buffers interleaved. Default -b main,system,crash.
adb logcat -b radio View the buffer that contains radio/telephony related messages.
adb logcat -b event View the buffer containing events-related messages.

12.4 adb logcat -c 清空日志

12.5 adb logcat -d Dump the log and then exit (don't block)

12.6 将日志输出到文件

adb logcat -f test.logs 不能用
adb logcat > test.logs

12.7 打印存在的缓存日志的大小

adb logcat -g

12.8 adb logcat -s tag打印指定tag的日志

adb logcat -s ActivityManager

12.9 adb logcat -v

Single format verbs:

  • brief — Display priority/tag and PID of the process issuing the message.
  • long       — Display all metadata fields, separate messages with blank lines.
    

  • process — Display PID only.

  • raw — Display the raw log message, with no other metadata fields.

  • tag — Display the priority/tag only.

  • thread — Display priority, PID and TID of process issuing the message.

  • threadtime — Display the date, invocation time, priority, tag, and the PID and TID of the thread issuing the message. (the default format).

  • time — Display the date, invocation time, priority/tag, and PID of the process issuing the message.

13 adb shell dumpsys: dumps system data

usage: dumpsys
To dump all services.
or:
dumpsys [-t TIMEOUT] [--help | -l | --skip SERVICES | SERVICE [ARGS]]
--help: shows this help
-l: only list services, do not dump them
-t TIMEOUT: TIMEOUT to use in seconds instead of default 10 seconds
--skip SERVICES: dumps all services but SERVICES (comma-separated list)
SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it

adb shell dumpsys
adb shell dumpsys battery
adb shell dumpsys batterystats

14.adb shell screencap 截屏

adb shell screencap -p /sdcard/test.png

15.adb shell screenrecored录屏

Options:
--size WIDTHxHEIGHT 设定视频分辨率,默认是手机的分辨率。
Set the video size, e.g. "1280x720". Default is the device's main display resolution (if supported), 1280x720 if not. For best results, use a size supported by the AVC encoder.
--bit-rate RATE 设定比特率。最高20M,默认4M。比特率越高,视频质量越高。
Set the video bit rate, in bits per second. Value may be specified as bits or megabits, e.g. '4000000' is equivalent to '4M'. Default 20Mbps.
--bugreport 在视频添加时间戳,便于问题分析
Add additional information, such as a timestamp overlay, that is helpful
in videos captured to illustrate bugs.
--time-limit TIME 设置时长,最大180秒
Set the maximum recording time, in seconds. Default / maximum is 180.
--verbose 标准输出显示有趣的信息
Display interesting information on stdout.


--help
Show this message.
adb shell screenrecord --size 720x1280 --bit-rate 2000000 --bugreport --time-limit 5 /sdcard/1943.mp4
adb shell screenrecord --size 720x1280 --bit-rate 2000000 --bugreport --time-limit 5 --verbose /sdcard/1943.mp4

16.adb shell ps

-A 列出所有的进程
-w 显示加宽可以显示较多的咨询
-au 显示较详细的咨询
-aux 显示所有包含其他使用者的进程
-au(x): USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

  • USER:行程拥有者
  • PID:pid
  • CPU:该进程使用的CPU资源百分比
  • MEM:占用的物理内存百分比
  • VSZ:占用的虚拟内存量,Kbytes
  • RSS:占用的固定的内存量,Kbytes
  • TTY:该进程是在那个终端机上面运作,若于终端机无关,则显示?。另外tty1-tty6是本机上面的登入者程序,若为pts/0等等的,则表示由网络连接进主机的程序的。
  • STAT:该程序目前的状态
    * D
    * R 该程序正在运作,或者是可被运作
    * S 该程序目前正在睡眠中,但可被某些讯号唤醒
    * T 该程序目前正在侦测或这是停止了
    * Z 该程序应该已经终止,但是其父程序却无法正常的终止它,造成僵尸程序状态
    * W
    * <
    * N
    * L
  • START:该进程被触发启动的时间
  • TIME:该进程实际使用CPU的时间
  • COMMAND:该程序的实际指令

17.adb shell top

top -n 2 更新2次后退出
top -d 3 更新时间为3秒
top -p pid 显示指定pid的进程信息
adb shell top -n 2 -d 5 -p 1048

18.adb shell getprop 机型信息

常用:
[ro.product.model]:机型名称
[ro.vendor.product.brand]: 品牌
[ro.build.version.release]: 系统

19.adb shell setprop

大神分享的安卓设备共享工具
http://adbshell.com/commands

posted on 2018-10-25 21:33  singleSpace  阅读(800)  评论(0编辑  收藏  举报