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?
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?
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
.
From my mind with echoing the file...
for i in *.img; do echo $i; adb push "$i" /sdcard/; done;
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 :)
Using find ({}
represents file name):
find *.img -exec adb push {} /storage/sdcard0 \;
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