0

How can we pull multiple files with the same extension by using "abd" command?

More details, I know that we can use command

adb pull sdcard/folder target-folder

to get all file of the folder.

I use this command to filter file in the adb shell.

ls -lR sdcard/folder | grep "ext"

But I want to filter some files with the same extension and pull them. So now, how can we combine two commands?

WesternGun
  • 11,303
  • 6
  • 88
  • 157
GAVD
  • 1,977
  • 3
  • 22
  • 40

2 Answers2

7
adb shell ls sdcard/folder/*.ext | tr '\r' ' ' | xargs -n1 adb pull

See adb pull multiple files

Community
  • 1
  • 1
  • Thanks for your answer. But when I run this command, I get this: /system/bin/sh: tr: not found /system/bin/sh: xargs: not found – GAVD Nov 23 '15 at 04:28
  • Are you sure you are not executing this command while being in shell session? – Roberto Artiles Astelarra Nov 23 '15 at 04:50
  • In fact, I already read the link in your answer, but it doesn't work with me. When I go to the shell of device by "adb shell", I type "tr --help" and "xargs --help", it returns the results in my command. – GAVD Nov 23 '15 at 05:04
  • The thing is that I don't really understand why it's trying to locate tr and xargs on your device instead of you local machine. "adb shell ls sdcard/folder/*.ext" command returns the result back to your terminal. If the command is executed while not being in adb shell session, then it should work out. Make sure that you are not executing the provided command while being in the shell session. – Roberto Artiles Astelarra Nov 23 '15 at 05:09
  • You can see what I tried [image](http://imgur.com/s9YI71g). In fact, I can run this command in the virtual machine which is ubuntu OS. But it doesn't work on Windows. Moreover, do you know where can it put the destination folder in this command? – GAVD Nov 23 '15 at 10:15
  • Ah, Windows. I recommend you to use cygwin (https://www.cygwin.com/) for such purposes. Regarding the destination folder you can define it this way: adb shell ls sdcard/folder/*.ext | tr '\r' ' ' | xargs -J % -n1 adb pull % – Roberto Artiles Astelarra Nov 23 '15 at 10:32
  • Good answer but, considering the comments, a bit terse. It might be worth you expanding on your answer to clarify that the command is for Linux (perhaps MacOS too?) and should be issued from a shell command prompt (terminal window) and assumes that the `adb`, `tr` and `xargs` tools are installed and accessible in the environment's path. – starfry Nov 24 '16 at 09:19
0

For Windows, even with gitbash installed (so find and xargs available), you have to use CMD for to iterate the file list.

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).

Find more info googling for /f and linux find.

WesternGun
  • 11,303
  • 6
  • 88
  • 157