Editing
ADB Commands
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Few bash snippets === @Source (https://jonfhancock.com/bash-your-way-to-better-android-development-1169bc3e0424) === Using tail -n //Use tail to remove the first line. Actually two lines. The first one is just a newline. The second is “List of devices attached.” $ adb devices | tail -n +2 === Using cut -sf // Cut the last word and any white space off the end of each line. $ adb devices | tail -n +2 | cut -sf -1 === Using xargs -I // Given the -I option, xargs will perform an action for each line of text that we feed into it. // We can give the line a variable name to use in commands that xargs can execute. $ adb devices | tail -n +2 | cut -sf -1 | xargs -I X echo X aw yiss === Three options below together // Will print android version of all connected devices adb devices | tail -n +2 | cut -sf -1 | xargs -I X adb -s X shell getprop ro.build.version.release === Using alias -- Example 1 alias tellMeMore=echo tellMeMore "hi there" Output => hi there -- Example 2 // Define alias alias apkinstall="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X install -r $1" // And you can use it later apkinstall ~/Downloads/MyAppRelease.apk // Install an apk on all devices -- Example 3 alias rmapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X uninstall $1" rmapp com.example.myapp // Uninstall a package from all devices -- Example 4 alias clearapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell pm clear $1" clearapp com.example.myapp // Clear data on all devices (leave installed) -- Example 5 alias startintent="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell am start $1" startintent https://twitter.com/JonFHancock // Launch a deep link on all devices Setting up your .bash_profile Finally, to make this all reusable even after rebooting your computer (aliases only last through the current session), we have to add these to your .bash_profile. You might or might not already have a .bash_profile, so let’s make sure we append to it rather than overwriting it. Just open a terminal, and run the following command touch .bash_profile && open .bash_profile This will create it if it doesn’t already exist, and open it in a text editor either way. Now just copy and paste all of the aliases into it, save, and close. alias startintent="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell am start $1" alias apkinstall="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X install -r $1" alias rmapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X uninstall $1" alias clearapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell pm clear $1" --------------------------- Sources: - Internet - https://www.automatetheplanet.com/adb-cheat-sheet/
Summary:
Please note that all contributions to SafeCodeGroup may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
SafeCode Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information