Android adb 拉取多个文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11074671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adb pull multiple files
提问by hsz
What is the best way to pull multiple files using
使用拉取多个文件的最佳方法是什么
adb pull
I have on my /sdcard/
25 files with following name:
我的/sdcard/
25 个文件中有以下名称:
gps1.trace
gps2.trace
...
gps25.trace
Wildcard does not work:
通配符不起作用:
adb pull /sdcard/gps*.trace .
回答by David Momenso
You can use xargs
and the result of the adb shell ls
command which accepts wildcards. This allows you to copy multiple files. Annoyingly the output of the adb shell ls
command includes line-feed control characters that you can remove using tr -d '\r'
.
您可以使用接受通配符xargs
的adb shell ls
命令的结果。这允许您复制多个文件。令人讨厌的是,该adb shell ls
命令的输出包括换行控制字符,您可以使用tr -d '\r'
.
Examples:
例子:
adb shell 'ls sdcard/gps*.trace' | tr -d '\r' | xargs -n1 adb pull
adb shell 'ls /sdcard/*.txt' | tr -d '\r' | sed -e 's/^\///' | xargs -n1 adb pull
回答by Ofir Luzon
adb pull
can receive a directory name instead of at file and it will pull the directory with all files in it.
adb pull
可以接收目录名称而不是文件,它将拉出包含所有文件的目录。
Pull all your gps traces in /sdcard/gpsTraces
在 /sdcard/gpsTraces 中提取所有 GPS 跟踪记录
adb pull /sdcard/gpsTraces/ .
Example of adb pull
and adb push
of recursive directories:
adb pull
和adb push
递归目录的示例:
C:\Test>adb pull /data/misc/test/ .
pull: building file list...
pull: /data/misc/test/test1/test2/test.3 -> ./test1/test2/test.3
pull: /data/misc/test/test1/test2/test.2 -> ./test1/test2/test.2
pull: /data/misc/test/test1/test2/test.1 -> ./test1/test2/test.1
pull: /data/misc/test/test1/test.3 -> ./test1/test.3
pull: /data/misc/test/test1/test.2 -> ./test1/test.2
pull: /data/misc/test/test1/test.1 -> ./test1/test.1
pull: /data/misc/test/test.3 -> ./test.3
pull: /data/misc/test/test.2 -> ./test.2
pull: /data/misc/test/test.1 -> ./test.1
9 files pulled. 0 files skipped.
0 KB/s (45 bytes in 0.093s)
C:\Test>adb push . /data/misc/test/
push: ./test1/test2/test.3 -> /data/misc/test/test1/test2/test.3
push: ./test1/test2/test.2 -> /data/misc/test/test1/test2/test.2
push: ./test1/test2/test.1 -> /data/misc/test/test1/test2/test.1
push: ./test1/test.3 -> /data/misc/test/test1/test.3
push: ./test1/test.2 -> /data/misc/test/test1/test.2
push: ./test1/test.1 -> /data/misc/test/test1/test.1
push: ./test.3 -> /data/misc/test/test.3
push: ./test.2 -> /data/misc/test/test.2
push: ./test.1 -> /data/misc/test/test.1
9 files pushed. 0 files skipped.
0 KB/s (45 bytes in 0.062s)
回答by Posting as a guesty-guest
./adb pull /sdcard
<-- fails
./adb pull /sdcard
<-- 失败
./adb pull /sdcard/
<-- works recursively - note the trailing slash
./adb pull /sdcard/
<-- 递归工作-注意尾部斜杠
Tested with Nexus 5 and adb downloaded March 2014.
使用 Nexus 5 和 2014 年 3 月下载的 adb 进行测试。
回答by themuddler
Even though adb pull
command started accepting folder name for the remote parameter, I still prefer to use tar
command. It provides more flexibility - allows for file name patterns (both includeand exclude), symlink control, preserves file permissions. Since Android 6.0 you can use a built-in. Before that you had to use 3rd-party tools like busybox
:
即使adb pull
command 开始接受远程参数的文件夹名称,我仍然更喜欢使用tar
command。它提供了更多的灵活性——允许文件名模式(包括和排除)、符号链接控制、保留文件权限。从 Android 6.0 开始,您可以使用内置的。在此之前,您必须使用 3rd-party 工具,例如busybox
:
adb exec-out tar c sdcard/amazonmp3 > amazon.tar
Make sure to omit the leading /
in your path.
确保省略/
路径中的前导。
回答by cardeol
I have created this for Windows boxes, It is very useful to transfer files using wildcards without mounting the filesystem. You can include this script somewhere in your path env.
我为 Windows 机器创建了这个,使用通配符传输文件而不安装文件系统非常有用。您可以在路径 env 中的某处包含此脚本。
adbpull.bat
adbpull.bat
@echo off
setlocal enabledelayedexpansion
if %1.==. (
echo Wilcard parameter is required.
goto end
)
for /F "tokens=* USEBACKQ" %%F in (`adb shell ls %1`) do (
set text=%%F
set mfile=!text:~0,-1!
adb pull "!mfile!"
)
:end
endlocal
Example:
adbpull /sdcard/DCIM/Camera/IMG_2016*
例子:
adbpull /sdcard/DCIM/Camera/IMG_2016*
回答by ishmael
Parsing the output from 'ls' is generally a bad idea. Instead, use 'find'.
解析 'ls' 的输出通常是一个坏主意。相反,使用“查找”。
adb shell 'find /sdcard/ -name "gps*.trace" -print0' | xargs -0 -n 1 adb pull
回答by qdiesel
ADBFS a FUSE Filesystem for Android Debug Bridgeif you are using linux or mac
如果您使用的是 linux 或 mac,则ADBFS 是用于 Android 调试桥的 FUSE 文件系统
回答by Palani
Directory pull is available on new android tools. ( I don't know from which version it was added, but its working on latest ADT 21.1 )
目录拉取可在新的 android 工具上使用。(我不知道它是从哪个版本添加的,但它适用于最新的 ADT 21.1)
adb pull /sdcard/Robotium-Screenshots
pull: building file list...
pull: /sdcard/Robotium-Screenshots/090313-110415.jpg -> ./090313-110415.jpg
pull: /sdcard/Robotium-Screenshots/090313-110412.jpg -> ./090313-110412.jpg
pull: /sdcard/Robotium-Screenshots/090313-110408.jpg -> ./090313-110408.jpg
pull: /sdcard/Robotium-Screenshots/090313-110406.jpg -> ./090313-110406.jpg
pull: /sdcard/Robotium-Screenshots/090313-110404.jpg -> ./090313-110404.jpg
5 files pulled. 0 files skipped.
61 KB/s (338736 bytes in 5.409s)
回答by FuriousGeorge
building on David's answer, I find this to be slightly better:
以大卫的回答为基础,我发现这要好一些:
adb shell ls /foo | tr -d '\r' | xargs -n1 adb pull
In addition to it being one character less to type (big deal) it doesn't convert the -r
into a space. This is a significant difference, as if you try to do
除了输入少一个字符(大不了)之外,它不会将其-r
转换为空格。这是一个显着的差异,就好像你试图做
adb shell ls /foo/myFile* | tr '\r' ' ' | xargs -i -n1 adb pull {} someDir
you'll get error saying
你会得到错误说
remote object '/foo/myFile1 ' does not exist
Instead you can do this, which will work:
相反,您可以这样做,这将起作用:
adb shell ls /foo/myFile* | tr -d '\r' | xargs -i -n1 adb pull {} someDir
回答by srinivasu u
Wild cards work in my case, I have been using following simple script to import Whatsapp Images of my virtual device in to my desktop
通配符适用于我的情况,我一直在使用以下简单脚本将我的虚拟设备的 Whatsapp 图像导入到我的桌面
#! /bin/bash
mkdir -p ~/Pictures/Pictures_adb
rm -f ~/Pictures/Pictures_adb/*
cd ~/Pictures/Pictures_adb
adb root
adb shell 'cp /data/media/0/WhatsApp/Media/WhatsApp\ Profile\ Photos/* /sdcard/Pictures/;exit'
adb pull /sdcard/Pictures
mv ~/Pictures/Pictures_adb/Pictures/* ~/Pictures/Pictures_adb/
rmdir ~/Pictures/Pictures_adb/Pictures
cd