44

I want to push some files of the same type (.img) to the /sdcard partition of the phone with a single command. But the wildcard does not work:

adb push *.img /sdcard/

Is there any way I can achieve that?

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
john
  • 451
  • 1
  • 4
  • 4

5 Answers5

56

Copy the *.img files to an empty directory, then push the directory (adb push /tmp/images /storage/sdcard0). adb will push all files in that directory to your designated location.

BTW, /sdcard as a path has been obsolete for quite some time, so please make sure you use a destination that exists and is supported by your device. Most Android 2.x/3.x/4.0 devices use /mnt/sdcard; Android 4.1 uses /storage/sdcard0.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Well I already did the "folder trick" but I was wondering if ADB supports wildcards.Hmm I never had a problem with /sdcard/ but I 've only used it on 4.1.1 (4.1.2 as of lately) in my Galaxy Nexus.Thanks a lot for answering! – john Oct 15 '12 at 21:03
  • 4
    @john: "I was wondering if ADB supports wildcards" -- it does not seem to. – CommonsWare Oct 15 '12 at 21:04
  • In that case I am considering the folder trick you suggested as the answer.Thanks again! – john Oct 15 '12 at 21:50
22

From my mind with echoing the file...

for i in *.img; do echo $i; adb push "$i" /sdcard/; done;
Nicolas Raoul
  • 58,567
  • 58
  • 222
  • 373
The Doctor
  • 223
  • 3
  • 6
18

Assuming you are using Windows, You can use a for loop to find files with an extension and do an adb push with that file like this in command line

for %i in (*.img) do adb push %i /sdcard/folderName/%i

If you are saving it as a batch file then make sure to add an extra "%" before "%i" like below

 for %%i in (*.img) do adb push %%i /sdcard/folderName/%%i

If you are using GNU/Linux, you can use this command which basically does the same thing

for f in *.img; do adb push $f /sdcard/folderName/$f; done

Hope it helped :)

Coding Otaku
  • 453
  • 7
  • 17
4

Using find ({} represents file name):

find *.img -exec adb push {} /storage/sdcard0 \;
bacv
  • 41
  • 1
  • 1
1

I have a script that does it (dash, Ubuntu Precise).

mpush:

#D=echo
D=
S=
if [ $1 == "-s" ]; then
    S="-s $2"
    shift
    shift
fi
if [ $# -lt 2 ]; then
    echo "Usage: $0 directory files..."
else
DIR=$1
shift
for f in $*
do
  #echo "Processing $DIR/$f file..."
  echo ~/aspt/adb ${S} push "$f" "$DIR/$f"
  ${D} ~/aspt/adb ${S} push "$f" "$DIR/$f"
done
fi

Usage:

mpush /sdcard/ libMyLib.so
mpush /sdcard/ libFirst.so libSecond.so
mpush /sdcard/ *
mpush -s 109d8a6fe0678a3 /sdcard/ *

The first two lines are left there for debugging: you can change the first two lines to

D=echo
#D=

and have the script print the adb push commands instead of executing them.

UPDATE: added ability to push to all attached devices (the -all switch)

#D=echo
D=
S=
if [ $1 == "-2all" -o $1 == "-all" ]; then
  shift
  DEVICES=`~/aspt/adb devices | tail -n +2 | awk '{print $1}'`
  if [ $# -lt 2 ]; then
      echo "Usage: $0 [options] directory files..."
      echo "Options:"
      echo "-s device-id -- push to the specified device"
      echo "-all or -2all -- push to all devices"
  else
    DIR=$1
    shift
    for d in $DEVICES
    do
      for f in $*
      do
    #echo "Processing $DIR/$f file..."
    echo ~/aspt/adb -s $d push "$f" "$DIR/$f"
    ${D} ~/aspt/adb -s $d push "$f" "$DIR/$f"
      done
    done
  fi
else
  if [ $1 == "-s" ]; then
      S="-s $2"
      shift
      shift
  fi
  if [ $# -lt 2 ]; then
      echo "Usage: $0 [options] directory files..."
      echo "Options:"
      echo "-s device-id -- push to the specified device"
      echo "-all or -2all -- push to all devices"
  else
    DIR=$1
    shift
    for f in $*
    do
      #echo "Processing $DIR/$f file..."
      echo ~/aspt/adb ${S} push "$f" "$DIR/$f"
      ${D} ~/aspt/adb ${S} push "$f" "$DIR/$f"
    done
  fi
fi
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127