Android Debug Bridge (adb) commands are very useful while debugging any Android device but at the same time it’s difficult to find all the commands at one place.
In this article, you will find 200+ ADB, shell and fastboot commands which are commonly used for debugging Android devices. Using these commands can reduce the required efforts and can help achieve the required result in less time.
Below is the list of commands which can be executed from command prompt or terminal on Android devices while the device is connected with the computer with USB debugging turned on.
ADB commands to connect and list devices:
If anyone has used ADB in the past then they must have used ‘adb devices’ to list all the connected devices. However, it’s not just limited to listing the devices, we can connect devices using wires or wirelessly and even control the ADB server. Here are the few commands which can help to connect and list the devices.
Use | Command |
To List all connected devices via adb | adb devices |
To List connected devices (-l for long output) | adb devices -l |
To list all devices connected via USB or To restart adb device in USB mode | adb usb |
To list all forward socket connections | adb forward –list |
To set up port forwarding (sets up forwarding of computer port 6123 to Android device port 7123) | adb forward tcp:6123 tcp:7123 |
To start the ADB server process | adb start-server |
To terminates the adb server process | adb kill-server |
To Set the target device to listen for a TCP/IP connection on port 5555Connect a device using Wi-Fi network.Confirm that your host computer is also connected to the Android device over Wi-Fi Help Text: disconnect the USB cable from the Android devicefind your Android device IP address at Settings > About phone > Status > IP addressList of devices attached192.xxx.xxx.xx:5555 device | adb tcpip 5555adb connect 192.xxx.xxx.xxadb devices |
ADB and shell commands to manage applications and get the application details:
The basic operations which everyone perform using ADB commands are to install and uninstall applications. ADB commands are also used to get the information of the applications installed on the device. Below are some ADB and shell commands to manage and get information about applications on the device.
Use | Command |
To push a single application to the device and install. | adb install <apk_name.apk> |
To push multiple applications to the device and install. | adb install-multiple <apkname.apk> <apkname2.apk> |
To push multiple applications to the device and install it automatically. | adb install-multi-package <apkname.apk> <apkname2.apk> |
To replace existing application by keeping its data. | adb install -r <apkname.apk> |
To install apk in external storage | adb install -s <apkname.apk> |
To allow test packages | adb install -t <apkname.apk> |
To uninstall apk by package name | adb uninstall <package_name_of_apk> |
To uninstall apk by package name while keeping cache and app data | adb uninstall -k <package_name_of_apk> |
To clear application data by package name | adb shell pm clear <package_name_of_apk> |
To uninstall system application by package name | adb shell pm uninstall -k –user 0 <package_name_of_apk> |
To disable application by package name | adb shell pm disable <package_name_of_apk> |
To disable application by package name for system user | adb shell pm disable-user –user 0 <package_name_of_apk> |
To disable re-enable disabled application by package name | adb shell pm enable <package_name_of_apk> |
To hide application by package name | adb shell pm hide <package_name_of_apk> |
To unhide application by package name | adb shell pm unhide <package_name_of_apk> |
To suspend any application by package name | adb shell pm suspend <package_name_of_apk> |
To re-enable suspended application by package name | adb shell pm unsuspend <package_name_of_apk> |
To list package name of all installed apks | adb shell pm list packages |
To list package name of all system apps | adb shell pm list packages -s |
To list package name of third party apps installed on the device | adb shell pm list packages -3 |
To list package name of disabled apps on the device | adb shell pm list packages -d |
To list package name of only enabled apps on the device | adb shell pm list packages -e |
To list package name of uninstalled apps from the device | adb shell pm list packages -u |
ADB commands to reboot device:
While debugging an android device, rebooting the device or rebooting in the recovery mode or bootloader mode is required for operations like sideloading any image or application. Below are some commands to achieve the same.
Use | Command |
To reboot the device | adb reboot |
To reboot device in bootloader or fastboot mode | adb reboot bootloader |
To reboot device in recovery mode | adb reboot recovery |
To restart ADB device with root permission | adb root |
To restart ADB device without root permission | adb unroot |
To manually install OTA package using recovery mode | adb sideload ota-updatefile.zip |
ADB commands for collecting logs and bug report:
Logs and Bug Reports contain useful information related to application and are important for developers while fixing bugs or making changes in the application. Here are some commands which are useful for taking bug reports and collecting logs.
Use | Command |
To display full logcat data on the computer screen | adb logcat |
To clear current logcat data | adb logcat -c |
To save current logcat data in local file | adb logcat -d <path> |
To generate bug report of connected device | adb bugreport <path> |
To get the serial number of connected device | adb get-serialno |
To wait for android device until the current process is completed | adb wait-for-device |
To get the device state in the terminal/command prompt | adb get-state |
To list JDWP (Java Debug Wire Protocol) processes of android device | adb jdwp |
ADB commands to take backup and restore:
It’s always a good idea to take a backup of your device’s data so that it can be restored later whenever it’s required but if you are unlocking the bootloader or debugging the device then it’s highly recommended to take backup. Here are some commands which can help you with the same.
Use | Command |
To take full backup of android device to computer | adb backup // |
To restore backup from computer to device | adb restore // |
To take backup of apps and settings | adb backup -apk -all -f backup.ab |
To take backup of applications and application settings and shared storage | adb backup -apk -shared -all -f backup.ab |
To take backup of only third party applications. | adb backup -apk -nosystem -all -f backup.ab |
To connect to device using its ip address | adb connect ip_address_of_device |
To restore previously created backup | adb restore backup.ab |
ADB and shell commands to perform file operations:
Performing copy-paste using explorer requires a lot of time and also compared to ADB it’s a little slow. You must have used ADB push and ADB pull for file operations but here are some more commands which can help you more with file operations.
Use | Command |
To copy or transfer a file from a device’s storage to a computer. | adb pull /system/app/<apkname.apk> |
To transmit or push a file from a computer to a device | adb push /local/path/<apkname.apk> /sdcard/apps/ |
To copy files inside device storage from one folder to another folder. | adb shell<enter>cp /sdcard/<filename.extension> /sdcard/foldername |
To move files inside device storage from one folder to another folder. | adb shell<enter>mv /sdcard/<filename.extension> /sdcard/foldername |
To move file inside the device storage and rename the file in destination folder | adb shell<enter>mv /sdcard/<filename.extension> /sdcard/apps/<newfilename.extension> |
Shell commands to get and change display resolution:
Information like screen resolution, pixel density and refresh rate are usually not getting displayed in the device and to get such information the user has to struggle a lot in Android settings and it’s even difficult to change it. Below are some commands to get the same information and change it using shell.
Use | Command |
To start remote shell console | adb shell |
To get pixel density, screen resolution, refresh rate and DPI information of android device | adb shell wm density |
To change screen resolution of android deviceNote: enter values based on the supported resolution of device | adb shell wm size 1080×2220 |
To change pixel density of android deviceNote: enter values based on the supported density of device | adb shell wm density 480 |
Shell commands to change directory to some important file location:
Using ADB, users can only perform 1 operation at a time on device storage but shell gives an advantage here to move inside any directory and then perform any operations on the same folder. Here are some important directories which are really useful.
Use | Command |
To start remote shell console | adb shell |
To change directory to /system | adb shell<enter>cd /system |
To delete file from device | adb shell<enter>rm -f /sdcard/<apkname.apk> |
To delete folder from device | adb shell<enter>rm -d /sdcard/test |
To create folder in device | adb shell<enter>mkdir /sdcard/test |
To check network statistic of android device | adb shell<enter>netstat |
To get IP address information of device’s WIFI | adb shell<enter>ip -f inet addr show wlan0 |
To get the list and monitor all process running on android device | adb shell<enter>top |
To get the properties of android build.prop configuration | adb shell<enter>getprop ro.build.version.sdk |
To Set/replace the properties of android build.prop configuration | adb shell<enter>setprop net.dns1 4.4.4.0 |
Shell commands to get the device stats:
Using shell commands users can get the information related to software and hardware for battery, display and battery stat which are useful for building an application. Below are the commands to get them.
Use | Command |
To get display information of device relating to software and hardware configuration | adb shell dumpsys display |
To get battery information of device relating to software and hardware configuration | adb shell dumpsys battery |
To get battery stats information of device relating to software and hardware configuration | adb shell dumpsys batterystats |
Shell commands to send SMS & take screenshot / to record screen:
Screen Record functionality is not available with old android devices but shell scripts are there to overcome that limitation. Also, some users don’t want to even touch the devices while the device is connected for debugging. So, the user needs commands to perform all those operations from the computer. Here are a few commands to perform those operations remotely from the computer.
Use | Command |
To send SMS from android device using ADB | adb shell am start -a android.intent.action.SENDTO -d sms:<phonenumber> –es sms_body “<SMS Text>” –ez exit_on_sent true adb shell input keyevent 22adb shell input keyevent 66 |
To take screenshot using ADB command | adb shell screencap /sdcard/screenshot.png |
To start screen recording using ADB command Note: To stop the screen recording press CTRL+C or COMMAND+C | adb shell screenrecord /sdcard/movie.mp4 |
To start screen recording by defining output resolution using ADB command. Note:1. To stop the screen recording press CTRL+C or COMMAND+C2. Enter resolution values based on the supported resolution of the device. | adb shell screenrecord –size 1440 x 2960 /sdcard/movie.mp4 |
To start screen recording using ADB command and set recording duration. Note: Replace ‘36’ with desired value in seconds. | adb shell screenrecord –time-limit 36 /sdcard/movie.mp4 |
To start screen recording using ADB command and set the bitrate of the video output file. | adb shell screenrecord –bit-rate 1500000 /sdcard/movie.mp4 |
Shell Commands to perform key operations:
Most Android developers and testers want to automate actions on Android devices but it needs a separate setup to achieve it. While ADB provides some inbuilt commands to perform those actions. Below are the key event commands of shell to perform action remotely from computer:
Use | Command |
To press HOME button using ADB | adb shell input keyevent 3oradb shell am start -W -c android.intent.category.HOME -a android.intent.action.MAIN |
To press BACK button using ADB | adb shell input keyevent 4 |
To press CALL button using ADB | adb shell input keyevent 5 |
To press END CALL button using ADB | adb shell input keyevent 6 |
To to toggle device to ON/OFF | adb shell input keyevent 26 |
To launch camera using ADB | adb shell input keyevent 27 |
To launch default browser using ADB | adb shell input keyevent 64 |
To press enter using ADB | adb shell input keyevent 66 |
To press delete or backspace using ADB | adb shell input keyevent 67 |
To launch contacts list using ADB | adb shell input keyevent 207 |
To turn down brightness level using ADB | adb shell input keyevent 220 |
To turn up brightness level using ADB | adb shell input keyevent 221 |
To perform Cut (ctrl+x) operation on selected item using ADB command | adb shell input keyevent 277 |
To perform Copy (ctrl+c) operation on selected item using ADB command | adb shell input keyevent 278 |
To perform Paste operation (ctrl+v) on selected item using ADB command | adb shell input keyevent 279 |
To pass keycode(keyboard value) unknown/0 using ADB | adb shell input keyevent 0 |
To pass keycode(keyboard value) MENU/SOFT_LEFT using ADB | adb shell input keyevent 1 |
To pass keycode(keyboard value) SOFT_RIGHT using ADB | adb shell input keyevent 2 |
To pass keycode(keyboard value) HOME using ADB | adb shell input keyevent 3 |
To pass keycode(keyboard value) BACK using ADB | adb shell input keyevent 4 |
To pass keycode(keyboard value) CALL using ADB | adb shell input keyevent 5 |
To pass keycode(keyboard value) END CALL using ADB | adb shell input keyevent 6 |
To pass keycode(keyboard value) 0 using ADB | adb shell input keyevent 7 |
To pass keycode(keyboard value) 1 using ADB | adb shell input keyevent 8 |
To pass keycode(keyboard value) 2 using ADB | adb shell input keyevent 9 |
To pass keycode(keyboard value) 3 using ADB | adb shell input keyevent 10 |
To pass keycode(keyboard value) 4 using ADB | adb shell input keyevent 11 |
To pass keycode(keyboard value) 5 using ADB | adb shell input keyevent 12 |
To pass keycode(keyboard value) 6 using ADB | adb shell input keyevent 13 |
To pass keycode(keyboard value) 7 using ADB | adb shell input keyevent 14 |
To pass keycode(keyboard value) 8 using ADB | adb shell input keyevent 15 |
To pass keycode(keyboard value) 9 using ADB | adb shell input keyevent 16 |
To pass keycode(keyboard value) STAR using ADB | adb shell input keyevent 17 |
To pass keycode(keyboard value) POUND using ADB | adb shell input keyevent 18 |
To pass keycode(keyboard value) DPAD_UP using ADB | adb shell input keyevent 19 |
To pass keycode(keyboard value) DPAD_DOWN using ADB | adb shell input keyevent 20 |
To pass keycode(keyboard value) DPAD_LEFT using ADB | adb shell input keyevent 21 |
To pass keycode(keyboard value) DPAD_RIGHT using ADB | adb shell input keyevent 22 |
To pass keycode(keyboard value) DPAD_CENTER using ADB | adb shell input keyevent 23 |
To pass keycode(keyboard value) VOLUME_UP using ADB | adb shell input keyevent 24 |
To pass keycode(keyboard value) VOLUME_DOWN using ADB | adb shell input keyevent 25 |
To pass keycode(keyboard value) POWER using ADB | adb shell input keyevent 26 |
To pass keycode(keyboard value) CAMERA using ADB | adb shell input keyevent 27 |
To pass keycode(keyboard value) CLEAR using ADB | adb shell input keyevent 28 |
To pass keycode(keyboard value) A using ADB | adb shell input keyevent 29 |
To pass keycode(keyboard value) B using ADB | adb shell input keyevent 30 |
To pass keycode(keyboard value) C using ADB | adb shell input keyevent 31 |
To pass keycode(keyboard value) D using ADB | adb shell input keyevent 32 |
To pass keycode(keyboard value) E using ADB | adb shell input keyevent 33 |
To pass keycode(keyboard value) F using ADB | adb shell input keyevent 34 |
To pass keycode(keyboard value) G using ADB | adb shell input keyevent 35 |
To pass keycode(keyboard value) H using ADB | adb shell input keyevent 36 |
To pass keycode(keyboard value) I using ADB | adb shell input keyevent 37 |
To pass keycode(keyboard value) J using ADB | adb shell input keyevent 38 |
To pass keycode(keyboard value) K using ADB | adb shell input keyevent 39 |
To pass keycode(keyboard value) L using ADB | adb shell input keyevent 40 |
To pass keycode(keyboard value) M using ADB | adb shell input keyevent 41 |
To pass keycode(keyboard value) N using ADB | adb shell input keyevent 42 |
To pass keycode(keyboard value) O using ADB | adb shell input keyevent 43 |
To pass keycode(keyboard value) P using ADB | adb shell input keyevent 44 |
To pass keycode(keyboard value) Q using ADB | adb shell input keyevent 45 |
To pass keycode(keyboard value) R using ADB | adb shell input keyevent 46 |
To pass keycode(keyboard value) S using ADB | adb shell input keyevent 47 |
To pass keycode(keyboard value) T using ADB | adb shell input keyevent 48 |
To pass keycode(keyboard value) U using ADB | adb shell input keyevent 49 |
To pass keycode(keyboard value) V using ADB | adb shell input keyevent 50 |
To pass keycode(keyboard value) W using ADB | adb shell input keyevent 51 |
To pass keycode(keyboard value) X using ADB | adb shell input keyevent 52 |
To pass keycode(keyboard value) Y using ADB | adb shell input keyevent 53 |
To pass keycode(keyboard value) Z using ADB | adb shell input keyevent 54 |
To pass keycode(keyboard value) COMMA using ADB | adb shell input keyevent 55 |
To pass keycode(keyboard value) PERIOD using ADB | adb shell input keyevent 56 |
To pass keycode(keyboard value) ALT_LEFT using ADB | adb shell input keyevent 57 |
To pass keycode(keyboard value) ALT_RIGHT using ADB | adb shell input keyevent 58 |
To pass keycode(keyboard value) SHIFT_LEFT using ADB | adb shell input keyevent 59 |
To pass keycode(keyboard value) SHIFT_RIGHT using ADB | adb shell input keyevent 60 |
To pass keycode(keyboard value) TAB using ADB | adb shell input keyevent 61 |
To pass keycode(keyboard value) SPACE using ADB | adb shell input keyevent 62 |
To pass keycode(keyboard value) SYM using ADB | adb shell input keyevent 63 |
To pass keycode(keyboard value) EXPLORER using ADB | adb shell input keyevent 64 |
To pass keycode(keyboard value) ENVELOPE using ADB | adb shell input keyevent 65 |
To pass keycode(keyboard value) ENTER using ADB | adb shell input keyevent 66 |
To pass keycode(keyboard value) DEL using ADB | adb shell input keyevent 67 |
To pass keycode(keyboard value) GRAVE using ADB | adb shell input keyevent 68 |
To pass keycode(keyboard value) MINUS using ADB | adb shell input keyevent 69 |
To pass keycode(keyboard value) EQUALS using ADB | adb shell input keyevent 70 |
To pass keycode(keyboard value) LEFT_BRACKET using ADB | adb shell input keyevent 71 |
To pass keycode(keyboard value) RIGHT_BRACKET using ADB | adb shell input keyevent 72 |
To pass keycode(keyboard value) BACKSLASH using ADB | adb shell input keyevent 73 |
To pass keycode(keyboard value) SEMICOLON using ADB | adb shell input keyevent 74 |
To pass keycode(keyboard value) APOSTROPHE using ADB | adb shell input keyevent 75 |
To pass keycode(keyboard value) SLASH using ADB | adb shell input keyevent 76 |
To pass keycode(keyboard value) AT using ADB | adb shell input keyevent 77 |
To pass keycode(keyboard value) NUM using ADB | adb shell input keyevent 78 |
To pass keycode(keyboard value) HEADSETHOOK using ADB | adb shell input keyevent 79 |
To pass keycode(keyboard value) FOCUS using ADB | adb shell input keyevent 80 |
To pass keycode(keyboard value) PLUS using ADB | adb shell input keyevent 81 |
To pass keycode(keyboard value) MENU using ADB | adb shell input keyevent 82 |
To pass keycode(keyboard value) NOTIFICATION using ADB | adb shell input keyevent 83 |
To pass keycode(keyboard value) SEARCH using ADB | adb shell input keyevent 84 |
To pass keycode(keyboard value) MEDIA_PLAY/PAUSE using ADB | adb shell input keyevent 85 |
To pass keycode(keyboard value) MEDIA_STOP using ADB | adb shell input keyevent 86 |
To pass keycode(keyboard value) NEXT using ADB | adb shell input keyevent 87 |
To pass keycode(keyboard value) PREVIOUS using ADB | adb shell input keyevent 88 |
To pass keycode(keyboard value) MEDIA_REWIND using ADB | adb shell input keyevent 89 |
To pass keycode(keyboard value) MEDIA_FAST_FORWARD using ADB | adb shell input keyevent 90 |
To pass keycode(keyboard value) MUTE using ADB | adb shell input keyevent 91 |
To pass keycode(keyboard value) PAGE UP using ADB | adb shell input keyevent 92 |
To pass keycode(keyboard value) PAGE DOWN using ADB | adb shell input keyevent 93 |
To pass keycode(keyboard value) PICT SYMBOLS using ADB | adb shell input keyevent 94 |
To pass keycode(keyboard value) MOVE_HOME using ADB | adb shell input keyevent 122 |
To pass keycode(keyboard value) MOVE_END using ADB | adb shell input keyevent 123 |
Fastboot commands for flashing:
Fastboot enables options for users to flash custom image and recovery files using fastboot mode. Some useful operations and it’s commands are listed below:
Use | Command |
To list all fastboot devices | fastboot devices |
To unlock bootloader of connected fastboot device | fastboot oem unlock |
To re-lock bootloader of connected fastboot device | fastboot oem lock |
To reboot device in fastboot or bootloader mode from fastboot mode | fastboot reboot bootloader |
To flash boot image using fastboot mode | fastboot flash boot boot.img |
To flash recovery image using fastboot mode | fastboot flash recovery recovery.im |
To boot custom Image in device without flashing the image file | fastboot boot filename.img |
Shell commands to get the device information:
Device information such as IMEI, Serial Number and also files available in device storage are important for us but at the same time it’s not easy to find some of this information as it’s hidden for users like system storage where firmware files are available. Some of this information are required while debugging the device. Some commands to get this information are given below:
Use | Command |
To list directory content | adb shell ls |
To print size of each file in selected directory | adb shell ls -s |
To print list of subdirectories recursively | adb shell ls -R |
To print state of device | adb get-statе |
To print IMEI of connected device | adb shell dumpsys iphonesybinfo |
To print information related to connectivity like TCP Ip and connections | adb shell netstat |
To print information of current working directory | adb shell pwd |
To print list of phone features | adb shell pm list features |
To print list of all services of device | adb shell service list |
To print information of application activity by package and activity name | adb shell dumpsys activity <package>/<activity> |
To print process status | adb shell ps |
To print current display resolution information | adb shell wm size |
To print activity of current opened application | dumpsys window windows | grep -E ‘mCurrentFocus|mFocusedApp’ |
To list the information of all opened apps | adb shell dumpsys package packages |
To get the information of particular application | adb shell dump <name> |
To get the path of application by package name | adb shell path <package> |
To change battery level of device (emulator)Note: Value can be 0 to 100 | adb shell dumpsys battery set level <n> |
To change battery status of device (emulator)Note: Value can be 0 to 3 which relates to state unknown, charging, discharging, not charging or full | adb shell dumpsys battery set status<n> |
To reset battery status of device (emulator) | adb shell dumpsys battery reset |
To change USB status of device (emulator)Note: Value can be 0 or 1 | adb shell dumpsys battery set usb <n> |
ADB is very useful. However, not being aware of some of these commands prevents users from utilising this powerful tool. I hope these commands will help you while using ADB. There are still some more commands which are not included here because of their limited and complicated use.. In case you wish to learn more about all supported commands on your device then ‘adb –help’ can help.
–
January 20, 2022Testing