天天看點

How to Use Android ADB Command Line Tool

Android Debug Bridge

(adb) is a tool that lets you manage the state of an emulator instance or Android phone. ADB is bundled with Android SDK package that can be downloaded from Android SDK download page. This tool is usefull for communicating with Android phone such as install application, copy files from/to device and perform some linux shell commands.

How to Install

Download and install

Java SDK

(Ex:jdk-6u20-windows-i586.exe)

Download

Android SDK

package (Ex:android-sdk_r06-windows.zip)

Extract SDK package into anywhere on your drive (Ex: D:\android-sdk-windows)

Phone Setup

In order to use ADB, you have to enable USB Debugging option in phone settings (Settings->Applications->Development)

How to Use Android ADB Command Line Tool

How to Use

  • Connect the phone to your pc/notebook usb port
  • Run Windows command line tool (cmd) and go to D:\android-sdk-windows\tool

Update!!

New Android SDK puts adb executable file on \platform-tools directory instead of tool. So the path should be D:\android-sdk-windows\platform-tools

Usefull Commands

1. Check connected phone

Syntax: adb devices
How to Use Android ADB Command Line Tool

2. Login to Android shell

Syntax: adb shell
How to Use Android ADB Command Line Tool

Note:

If you get ‘#’ after typing adb shell, you are already get root access on the phone, no need to type su. Otherwise if you get ‘$’ , type ‘su’ to get root access (only for rooted device).

3. Some usefull shell commands

  • ls

    List directory

Syntax: ls [path]

Example:

#ls /system/lib

  • cp

    Copy file or directory

Syntax: cp [options] source dest

To copy or delete files in Android root directories you have to change the directory access mode to ‘read and write (rw)’ using command: remount rw

#remount rw

#cp /sdcard/libsec-ril.so /system/lib

#remount ro

  • mv

    Move file or directory

Syntax: mv [options] source dest

#mv /system/lib/libsec-ril.so /sdcard/backup

  • chmod

    Change file/directory permission

Syntax: chmod [-R] mode[,mode] …. file

#chmod 0644 /system/lib/libsec-ril.so

  • rm

    Remove file or directory

Syntax: rm [options] file

#rm /system/lib/libsec-ril.so

4. Install application

You can use adb to install aplication from your local drive into phone.

Syntax: adb install appname.apk

D:\android-sdk-windows\tools\adb install D:\AnReboot.apk

How to Use Android ADB Command Line Tool

5. Copy files from phone to local drive

Syntax: adb pull source [destination]

D:\android-sdk-windows\tools\adb pull /sdcard/arm11-dvm.zip

D:\android-sdk-windows\tools\adb pull /sdcard/arm11-dvm.zip D:

How to Use Android ADB Command Line Tool

6. Copy files from local drive to phone

Syntax: adb push source destination

D:\android-sdk-windows\tools\adb push D:\AnReboot.apk /sdcard

How to Use Android ADB Command Line Tool
To See The Original Link Please Click Here
  1. 擷取序列号:

    adb get-serialno

  2. 檢視連接配接計算機的裝置:

    adb devices

  3. 重新開機機器:

    adb reboot

  4. 重新開機到bootloader,即刷機模式:

    adb reboot bootloader

  5. 重新開機到recovery,即恢複模式:

    adb reboot recovery

  6. 檢視log:

    adb logcat

  7. 終止adb服務程序:

    adb kill-server

  8. 重新開機adb服務程序:

    adb start-server

  9. 擷取機器MAC位址:

    adb shell cat /sys/class/net/wlan0/address

  10. 擷取CPU序列号:
adb shell cat /proc/cpuinfo           
  1. 安裝APK:
adb install <apkfile> //比如:adb install baidu.apk           
  1. 保留資料和緩存檔案,重新安裝apk:
adb install -r <apkfile> //比如:adb install -r baidu.apk           
  1. 安裝apk到sd卡:
adb install -s <apkfile> // 比如:adb install -s baidu.apk           
  1. 解除安裝APK:
adb uninstall <package> //比如:adb uninstall com.baidu.search           
  1. 解除安裝app但保留資料和緩存檔案:
adb uninstall -k <package> //比如:adb uninstall -k com.baidu.search           
  1. 啟動應用:
adb shell am start -n <package_name>/.<activity_class_name>           
  1. 檢視裝置cpu和記憶體占用情況:
adb shell top           
  1. 檢視占用記憶體前6的app:
adb shell top -m 6           
  1. 重新整理一次記憶體資訊,然後傳回:
adb shell top -n 1           
  1. 查詢各程序記憶體使用情況:
adb shell procrank           
  1. 殺死一個程序:
adb shell kill [pid]           
  1. 檢視程序清單:
adb shell ps           
  1. 檢視指定程序狀态:
adb shell ps -x [PID]           
  1. 檢視背景services資訊:
adb shell service list           
  1. 檢視目前記憶體占用:
adb shell cat /proc/meminfo           
  1. 檢視IO記憶體分區:
adb shell cat /proc/iomem           
  1. 将system分區重新挂載為可讀寫分區:
adb remount           
  1. 從本地複制檔案到裝置:
adb push <local> <remote>           
  1. 從裝置複制檔案到本地:
adb pull <remote>  <local>           
  1. 列出目錄下的檔案和檔案夾,等同于dos中的dir指令:
adb shell ls           
  1. 進入檔案夾,等同于dos中的cd 指令:
adb shell cd <folder>           
  1. 重命名檔案:
adb shell rename path/oldfilename path/newfilename           
  1. 删除system/avi.apk:
adb shell rm /system/avi.apk           
  1. 删除檔案夾及其下面所有檔案:
adb shell rm -r <folder>           
  1. 移動檔案:
adb shell mv path/file newpath/file           
  1. 設定檔案權限:
adb shell chmod 777 /system/fonts/DroidSansFallback.ttf           
  1. 建立檔案夾:
adb shell mkdir path/foldelname           
  1. 檢視檔案内容:
adb shell cat <file>           
  1. 檢視wifi密碼:
adb shell cat /data/misc/wifi/*.conf           
  1. 清除log緩存:
adb logcat -c           
  1. 檢視bug報告:
adb bugreport           
  1. 擷取裝置名稱:
adb shell cat /system/build.prop           
  1. 檢視ADB幫助:
adb help           
  1. 跑monkey:
adb shell monkey -v -p your.package.name 500           
  1. 通路資料庫SQLite3

    adb shell

    sqlite3

How to Use Android ADB Command Line Tool
How to Use Android ADB Command Line Tool

繼續閱讀