Common ADB commands

Keywords: shell Android Attribute Mac

ADB is very powerful, remember some ADB commands can help improve work efficiency.

  1. Get the serial number:

     adb get-serialno
  2. View the device that connects the computer:

     adb devices
  3. Restart the machine:

     adb reboot
  4. Restart to bootloader, brush mode:

     adb reboot bootloader
  5. Restart to recovery, i.e. recovery mode:

     adb reboot recovery
  6. View log:

     adb logcat
  7. Terminate the adb service process:

     adb kill-server
  8. Restart the adb service process:

     adb start-server
  9. Get the MAC address of the machine:

     adb shell  cat /sys/class/net/wlan0/address
  10. Get the CPU serial number:

    adb shell cat /proc/cpuinfo
  11. Install APK:

    adb install <apkfile> //For example: adb install baidu.apk
  12. Reserve data and cache files and reinstall apk:

    adb install -r <apkfile> //For example: adb install -r baidu.apk
  13. Install apk to sd card:

    adb install -s <apkfile> // For example: adb install -s baidu.apk
  14. Unload APK:

    adb uninstall <package> //For example: adb uninstall com.baidu.search
  15. Unload app but keep data and cached files:

    adb uninstall -k <package> //For example: ADB uninstall-k com.baidu.search
  16. Start the application:

    adb shell am start -n <package_name>/.<activity_class_name>
  17. Check device cpu and memory usage:

    adb shell top
  18. View app s that occupy the first 6 memory:

    adb shell top -m 6
  19. Refresh the memory information once, and then return:

    adb shell top -n 1
  20. Query the memory usage of each process:

    adb shell procrank
  21. Kill a process:

    adb shell kill [pid]
  22. View the process list:

    adb shell ps
  23. View the specified process status:

    adb shell ps -x [PID]
  24. View background services information:

    adb shell service list
  25. View the current memory footprint:

    adb shell cat /proc/meminfo
  26. View IO memory partitions:

    adb shell cat /proc/iomem
  27. Remount the system partition as a read-write partition:

    adb remount
  28. From local copy files to devices:

    adb push <local> <remote>
  29. Copy files from device to local:

    adb pull <remote>  <local>
  30. List the files and folders in the directory, which is equivalent to the dir command in dos:

    adb shell ls
  31. Entering a folder is equivalent to the cd command in dos:

    adb shell cd <folder>
  32. Rename the file:

    adb shell rename path/oldfilename path/newfilename
  33. Delete system/avi.apk:

    adb shell rm /system/avi.apk
  34. Delete folders and all files below them:

    adb shell rm -r <folder>
  35. Mobile files:

    adb shell mv path/file newpath/file
  36. Set file permissions:

    adb shell chmod 777 /system/fonts/DroidSansFallback.ttf
  37. New folder:

    adb shell mkdir path/foldelname
  38. View the file contents:

    adb shell cat <file>
  39. Check the wifi password:

    adb shell cat /data/misc/wifi/*.conf
  40. Clear log cache:

    adb logcat -c
  41. View bug reports:

    adb bugreport
  42. Get device name:

    adb shell cat /system/build.prop
  43. See ADB Help:

    adb help
  44. Running monkey:

    adb shell monkey -v -p your.package.name 500




Get the Android System Properties (adb shell getprop ***) data source

stay Android In the system, there are several configuration files needed to start the system under its root file system:
  1. /init.rc  
  2. /default.prop  
  3. /system/build.prop  

Usually we can get the setprop settings from the command getprop; before using these two commands, we first look at what's in build.prop.

adb shell cat /system/build.prop

The results are as follows: (Listed only in part)

ro.build.id=KOT49H
ro.build.display.id=KOT49H.20140814 test-keys
ro.build.version.incremental=20140814
ro.build.version.sdk=19
ro.build.version.codename=REL
ro.build.version.release=4.4.2
ro.build.date=2014-08-14 16:50:37
ro.product.model=K1
ro.product.brand=MBX
ro.product.name=K1
ro.product.device=K1
ro.product.board=K1
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.manufacturer=MBX
ro.product.locale.language=zh

Obviously, the data stored in this file is stored in this form of equal sign, and they appear in pairs of key values.

Now let's look at the results of getprop: (List only a few)

[ro.build.characteristics]: [mbx]
[ro.build.date.utc]: [1407987033]
[ro.build.date]: [2014-08-14 16:50:37]
[ro.build.description]: [k200-user 4.4.2 KOT49H 20140814 test-keys]
[ro.build.display.id]: [KOT49H.20140814 test-keys]
[ro.build.id]: [KOT49H]
[ro.build.product]: [K1]
[ro.build.version.codename]: [REL]
[ro.build.version.incremental]: [20140814]
[ro.build.version.release]: [4.4.2]
[ro.product.board]: [K1]
[ro.product.brand]: [MBX]
[ro.product.cpu.abi2]: [armeabi]
[ro.product.cpu.abi]: [armeabi-v7a
[ro.product.device]: [K1]
[ro.product.locale.language]: [zh]
[ro.product.locale.region]: [cn]
[ro.product.model]: [K1]
[ro.product.name]: [K1]

Therefore, getprop is to read out the information in the configuration file and display it to the user in the form of a dictionary.

Its format is as follows:
getprop [key] Gets the attribute value of the corresponding key
getprop lists all configuration property values
If you want to modify attributes, it's very simple. You just need to modify dictionary values, such as:
setprop [key] [value] sets the attribute value of the specified key;
watchprops monitors changes in system attributes and displays the changed values if the attributes of the system change during the period.
In fact, these three commands are all subcommands of toolbox. If you are interested, you can see the corresponding source code in the android source code: system/core/toolbox./

getprop looks at all the information parameters of the machine
getprop ro.serialno looks at the serial number of the machine
getprop ro.carrier to view the CID number of the machine
getprop ro.hardware view machine board code
getprop ro.bootloader view SPL(Hboot) version number


Posted by sdaniels on Thu, 11 Jul 2019 17:20:00 -0700