39

I'm attempting to use the adb pull command to copy only certain files (jpg) to my macbook. I tried "adb pull sdcard/mydir/*.jpg" but it apparently doesn't interpret wildcards. How can I get only the jpg files copied over? I have rooted the phone if that helps.

3 Answers 3

75

You can move your files to other folder and then pull whole folder.

adb shell mkdir /sdcard/tmp
adb shell mv /sdcard/mydir/*.jpg /sdcard/tmp # move your jpegs to temporary dir
adb pull /sdcard/tmp/ # pull this directory (be sure to put '/' in the end)
adb shell mv /sdcard/tmp/* /sdcard/mydir/ # move them back
adb shell rmdir /sdcard/tmp # remove temporary directory
4
  • This doesn't work for me. I try copying TWRP backups with adb pull /sdcard/TWRP/ TWRP and it creates a 1kb .twrps file and nothing else.
    – Celeritas
    Oct 12, 2016 at 3:44
  • Why to move files to another folder and then pull them? I only pulled the files from original folder (with "/" in the end) and it worked.
    – Mario Mey
    Jul 3, 2017 at 20:44
  • The move lets you single out .jpg files. Since shell mv allows wildcards in filepaths but pull doesn't, you can be as specific as you want with the move then do the general pull before moving things back.
    – NJTabit
    Dec 19, 2017 at 23:51
  • This one is a good idea to single out certain files. To make this process easier, one can install the ES-File to move and select files to another folder, and it would make one's life easier, and then just call adb pull command as listed by Michal to get all the files.
    – g5thomas
    Jun 22, 2018 at 19:07
15

Pull multiple files using regex:

Create pullFiles.sh:

#!/bin/bash
HOST_DIR=<pull-to>
DEVICE_DIR=/sdcard/<pull-from>
EXTENSION=".jpg"

for file in $(adb shell ls $DEVICE_DIR | grep $EXTENSION'$')
do
    file=$(echo -e $file | tr -d "\r\n"); # EOL fix
    adb pull $DEVICE_DIR/$file $HOST_DIR/$file;
done

Run it:

Make it executable: chmod +x pullFiles.sh

Run it: ./pullFiles.sh

Notes:

  • as is, won't work when filenames have spaces
  • includes a fix for end-of-line (EOL) on Android, which is a "\r\n"
5
  • 2
    On Linux, the osx fix needs to changed to tr -d "\r"
    – Jonathan
    Aug 22, 2014 at 16:28
  • 1) This seems to miss cases where there is a space in the filename. 2) The grep expression is underspecified (the . isn't being used correctly and it should end with a $ to match the wildcard *.txt)
    – Erick Wong
    May 18, 2015 at 1:48
  • @ErickWong That was a small snippet that worked for me, and I thought it would be nice to share it! It does NOT cover all cases of course, but feel free to edit it, to include the ending char $, and files with spaces!
    – Paschalis
    May 19, 2015 at 14:31
  • Worked for me only after removing the ending dollar sign from $EXTENSION$ Oct 24, 2017 at 10:43
  • @dafnahaktana The second denotes the ending char. It was working fine for me, but I guess in single quotes should be safer. I updated the answer.
    – Paschalis
    Oct 24, 2017 at 18:20
0

As to the short script, the following runs on my Linux host

#!/bin/bash
HOST_DIR=<pull-to>
DEVICE_DIR=/sdcard/<pull-from>
EXTENSION="\.jpg"

while read MYFILE ; do
    adb pull "$DEVICE_DIR/$MYFILE" "$HOST_DIR/$MYFILE"
done < $(adb shell ls -1 "$DEVICE_DIR" | grep "$EXTENSION")

"ls minus one" lets "ls" show one file per line, and the quotation marks allow spaces in the filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.