What is the best way to pull multiple files using
adb pull
I have on my /sdcard/
25 files with following name:
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
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
In Android, there are some folder with associated permissions! Some folder belong to root- or system user.
You guys should change the permissions of those files, folders before doing "adb pull".
The following commands could help:
adb shell
su
chmod -R 777 target_folder
exit
...
adb pull /.../target_folder/ . (current local folder)
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'
.
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
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.
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*
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 include and 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 exec-out tar c sdcard/amazonmp3 > amazon.tar
Make sure to omit the leading /
in your path.
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 )
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)