adb pull multiple files

AndroidAdb

Android Problem Overview


What is the best way to pull multiple files using

adb pull

I have on my /sdcard/ 25 files with following name:

gps1.trace
gps2.trace
...
gps25.trace

Wildcard does not work:

adb pull /sdcard/gps*.trace .

Android Solutions


Solution 1 - Android

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:

# Using a relative path
adb shell 'ls sdcard/gps*.trace' | tr -d '\r' | xargs -n1 adb pull
# Using an absolute path 
adb shell 'ls /sdcard/*.txt' | tr -d '\r' | sed -e 's/^\///' | xargs -n1 adb pull

Solution 2 - Android

adb pull can receive a directory name instead of at file and it will pull the directory with all files in it.

Pull all your gps traces in /sdcard/gpsTraces

adb pull /sdcard/gpsTraces/ . 

Example of adb pull and adb push of recursive directories:

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)

Solution 3 - Android

./adb pull /sdcard <-- fails

./adb pull /sdcard/ <-- works recursively - note the trailing slash

Tested with Nexus 5 and adb downloaded March 2014.

Solution 4 - Android

Parsing the output from 'ls' is generally a bad idea. Instead, use 'find'.

adb shell 'find /sdcard/ -name "gps*.trace" -print0' | xargs -0 -n 1 adb pull

Why you shouldn't parse the output of ls

Solution 5 - Android

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.

Solution 6 - Android

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*

Solution 7 - Android

Solution 8 - Android

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)

Solution 9 - Android

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 

Solution 10 - Android

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

#! /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

Solution 11 - Android

PowerShell:

adb shell ls /sdcard/gps*.trace | foreach {adb pull $_}

Solution 12 - Android

This is possible using adb exec-out. For example to get all of today's screenshots you can do:

adb exec-out "cd /sdcard/Pictures/Screenshots; tar c Screenshot_20210907*" | tar x

This will transfer all of the files inside a temporary tar archive and extract it to your current working directory. Credit is due to https://stackoverflow.com/a/39429196/3347392.

Solution 13 - Android

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhszView Question on Stackoverflow
Solution 1 - AndroidDavid MomensoView Answer on Stackoverflow
Solution 2 - AndroidOfir LuzonView Answer on Stackoverflow
Solution 3 - AndroidPosting as a guesty-guestView Answer on Stackoverflow
Solution 4 - AndroidishmaelView Answer on Stackoverflow
Solution 5 - AndroidthemuddlerView Answer on Stackoverflow
Solution 6 - AndroidcardeolView Answer on Stackoverflow
Solution 7 - AndroidqdieselView Answer on Stackoverflow
Solution 8 - AndroidPalaniView Answer on Stackoverflow
Solution 9 - AndroidFuriousGeorgeView Answer on Stackoverflow
Solution 10 - Androidsrinivasu uView Answer on Stackoverflow
Solution 11 - AndroidsamusView Answer on Stackoverflow
Solution 12 - Androiduser3347392View Answer on Stackoverflow
Solution 13 - AndroidTim LongView Answer on Stackoverflow