Running adb commands on all connected devices

前端 未结 6 1440
野性不改
野性不改 2020-12-24 13:30

Is there a way of running adb commands on all connected devices? To uninstall an app from all connected devices with \"adb uninstall com.example.android\".

The comma

6条回答
  •  感动是毒
    2020-12-24 13:58

    To add in the ~/.bashrc or ~/.zshrc:

    alias adb-all="adb devices | awk 'NR>1{print \$1}' | parallel -rkj0 --tagstring 'on {}: ' adb -s {}"

    Examples:

    • $ adb-all shell date
    • $ adb-all shell getprop net.hostname
    • $ adb-all sideload /path/to/rom.zip
    • $ adb-all install /path/filename.apk
    • $ adb-all push /usr/local/bin/frida-server-arm64 /data/local/tmp/frida-server

    Explanation: awk extracts the device id/host (first column: print $1) of every lines except the first one (NR>1) to remove the "List of devices attached" header line), then gnu parallel runs adb -s on whatever non-empty line (-r) in the order specified (-k, to avoid random order / fastest response order) and prepend each line with on :\t for clarity, all in parallel (-j0, possible to set another number to define how many adb should be ran in parallel instead of unlimited).

    :)

提交回复
热议问题