# ADB Commands **Adb is usually located in:** ```bash #Windows C:\Users\\AppData\Local\Android\sdk\platform-tools\adb.exe #MacOS /Users//Library/Android/sdk/platform-tools/adb ``` **Information obtained from:** [**http://adbshell.com/**](http://adbshell.com/)\*\*\*\* ## Connection ```text adb devices ``` This will list the connected devices; if "_**unathorised**_" appears, this means that you have to **unblock** your **mobile** and **accept** the connection. This indicates to the device that it has to start and adb server in port 5555: ```text adb tcpip 5555 ``` Connect to that IP and that Port: ```text adb connect : ``` If you get an error like the following in a Virtual Android software \(like Genymotion\): ```text adb server version (41) doesn't match this client (36); killing... ``` It's because you are trying to connect to an ADB server with a different version. Just try to find the adb binary the software is using \(go to `C:\Program Files\Genymobile\Genymotion` and search for adb.exe\) ### Several devices Whenever you find **several devices connected to your machine** you will need to **specify in which one** you want to run the adb command. ```bash adb devices List of devices attached 10.10.10.247:42135 offline 127.0.0.1:5555 device ``` ```bash adb -s 127.0.0.1:5555 shell x86_64:/ # whoami root ``` ### Port Tunneling In case the **adb** **port** is only **accessible** from **localhost** in the android device but **you have access via SSH**, you can **forward the port 5555** and connect via adb: ```bash ssh -i ssh_key username@10.10.10.10 -L 5555:127.0.0.1:5555 -p 2222 adb connect 127.0.0.1:5555 ``` ## Packet Manager ### Install/Uninstall #### adb install \[option\] <path> ```text adb install test.apk ``` ```text adb install -l test.apk forward lock application ``` ```text adb install -r test.apk replace existing application ``` ```text adb install -t test.apk allow test packages ``` ```text adb install -s test.apk install application on sdcard ``` ```text adb install -d test.apk allow version code downgrade ``` ```text adb install -p test.apk partial application install ``` #### adb uninstall \[options\] <PACKAGE> ```text adb uninstall com.test.app ``` ```text adb uninstall -k com.test.app Keep the data and cache directories around after package removal. ``` ### Packages Prints all packages, optionally only those whose package name contains the text in <FILTER>. #### adb shell pm list packages \[options\] <FILTER-STR> ```text adb shell pm list packages ``` ```text adb shell pm list packages -f #See their associated file. ``` ```text adb shell pm list packages -d #Filter to only show disabled packages. ``` ```text adb shell pm list packages -e #Filter to only show enabled packages. ``` ```text adb shell pm list packages -s #Filter to only show system packages. ``` ```text adb shell pm list packages -3 #Filter to only show third party packages. ``` ```text adb shell pm list packages -i #See the installer for the packages. ``` ```text adb shell pm list packages -u #Also include uninstalled packages. ``` ```text adb shell pm list packages --user #The user space to query. ``` #### adb shell pm path <PACKAGE> Print the path to the APK of the given . ```text adb shell pm path com.android.phone ``` #### adb shell pm clear <PACKAGE> Delete all data associated with a package. ```text adb shell pm clear com.test.abc ``` ## File Manager #### adb pull <remote> \[local\] Download a specified file from an emulator/device to your computer. ```text adb pull /sdcard/demo.mp4 ./ ``` #### adb push <local> <remote> Upload a specified file from your computer to an emulator/device. ```text adb push test.apk /sdcard ``` ## Screencapture/Screenrecord #### adb shell screencap <filename> Taking a screenshot of a device display. ```text adb shell screencap /sdcard/screen.png ``` #### adb shell screenrecord \[options\] <filename> Recording the display of devices running Android 4.4 \(API level 19\) and higher. ```text adb shell screenrecord /sdcard/demo.mp4 adb shell screenrecord --size adb shell screenrecord --bit-rate adb shell screenrecord --time-limit