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
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
-
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. 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. 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.– NJTabitDec 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.– g5thomasJun 22, 2018 at 19:07
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"
-
2
-
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) 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! 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. Oct 24, 2017 at 18:20
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.