如何使用 adb pull 从 Android 复制选定的文件

发布于 2024-12-23 08:03:13 字数 130 浏览 3 评论 0原文

我正在尝试使用 adb pull 命令仅将某些文件 (jpg) 复制到我的 MacBook。我尝试了“adb pull sdcard/mydir/*.jpg”,但它显然不能解释通配符。如何只复制 jpg 文件?如果有帮助的话我已经root了手机。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

总攻大人 2024-12-30 08:03:13

您可以将文件移动到其他文件夹,然后提取整个文件夹。

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

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
小忆控 2024-12-30 08:03:13

使用正则表达式拉取多个文件:

创建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'

运行它:

使其可执行:chmod +x pullFiles.sh

运行它:./pullFiles.sh< /code>

注意:

  • 按原样,当文件名有空格时将不起作用,
  • 包括对 Android 上行尾 (EOL) 的修复,即“\r\n”
) do file=$(echo -e $file | tr -d "\r\n"); # EOL fix adb pull $DEVICE_DIR/$file $HOST_DIR/$file; done

运行它:

使其可执行:chmod +x pullFiles.sh

运行它:./pullFiles.sh< /code>

注意:

  • 按原样,当文件名有空格时将不起作用,
  • 包括对 Android 上行尾 (EOL) 的修复,即“\r\n”

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'

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"
) 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"
┈┾☆殇 2024-12-30 08:03:13

至于简短的脚本,以下在我的 Linux 主机上运行

#!/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”让“ls”每行显示一个文件,引号允许文件名中包含空格。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文