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
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:
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
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
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.
I wanted to expand on David Momenso's answer and address the specific part of the question about wildcards. I turned his suggestion into a bash function that will allow for passing in a parameter that will append to the wildcard.
This a bash function that will allow for pulling all videos based on the date, utilizing the passed in parameter and wildcard.
I am using Windows adb.exe and gitbash, even syntax is right, adb.exe says it cannot find files if used in xargs.
You have to use cmd for loop:
for /f "delims=" %G in ('adb shell find sdcard/DCIM/Camera/20221111*') do adb pull -a "%G"
This will download all photos and videos matching the criteria(in my case, taken on the day 2022 Nov 11st).
查找更多信息谷歌for /f和linux find。
If you don't have find available(Gitbash not installed), a workaround is to move all files you want on phone to another new album and adb pull from there. Not a solution but a workaround.
adb pull -a sdcard/DCIM/new-album . # will pull all photos to a folder called "new-album"