简介
做android相关的工作基本都会用到adb,简单介绍下adb pull与adb push
从手机导出文件
adb pull <remote> <local> :Copies a specified file from an emulator/device instance to your development computer.
向手机导入文件
adb push <local> <remote>:Copies a specified file from your development computer to an emulator/device instance.
在命令行调用,首先要切到adb目录,然后就可以直接调用adb push和adb pull命令了
列子:
导入文件:adb push D:\test.apk /sdcard/tmp
导出文件:adb pull /sdcard/tmp/test.apk D:\
提示:在导入或者导出多个文件时,要先把文件都放到一个文件夹中,以文件夹的方式导入导出。
如果对手机下的没有访问权限,就不能导出。
模拟器默认赋予用户root权限
给一个上传文件的shell
Create pullFiles.sh
:
#!/bin/bash HOST_DIR=<pull-to> DEVICE_DIR=/sdcard/<pull-from> EXTENSION=".jpg" for file in $(adb shell ls $DEVICE_DIR | grep $EXTENSION$) do file=$(echo -e $file | tr -d "\r\n"); # EOL fix adb pull $DEVICE_DIR/$file $HOST_DIR/$file; done
Run it:
Make it executable: chmod +x pullFiles.sh
Run it: ./pullFiles.sh
Notes:
- as is, won't work when filenames have spaces
- includes a fix for end-of-line (EOL) on Android, which is a "\r\n"