HowTo: “ADB” – Command Line Tool

If someone finds a mistake, please notify me and I will correct it …

PLEASE NOTE THAT I AM NOT RESPONSIBLE FOR YOU MESSING UP YOUR PHONE!

Introduction
The Linux terminal is a command-line interface that you can use for all types of operation on the Android OS. A lot of users are afraid to use it because it ‘s not a GUI, and to be honest, if you don’t know the basics it’s pretty hard to learn by yourself.

How to Install

  • Download and install Java SDK
  • Download Android SDK package
  • Extract SDK package into anywhere on your drive (e.g.: 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

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


Notes:
* Don’t use it if you don’t know what you do!!!!
* Commands and folders are CASE-SENSITIVE (lall != laLl != Lall …)
* Commands can use easy-regular-expressions (e.g. rm *.lall -> deleted everything that ends with “.lall” in this directory)
* If a command completed successfully, it will say nothing and start a new line

Default adb commands

1.) Check connected phone

adb devices

2. Login to Android shell

adb shell

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” (su = substitute user) to get root access (only for rooted device).

3. show the Android-Logfile

adb logcat

V —> Verbose (lowest priority)
D —> Debug
I —> Info
W —> Warning
E —> Error
F —> Fatal
S —> Silent (highest priority, on which nothing is ever printed)

# e.g. Error messages

adb logcat *:E

radio —> View the buffer that contains radio/telephony related messages.
events —> View the buffer containing events-related messages.
main —> View the main log buffer (default)

# e.g. all event messages

adb logcat -b events

 

Some usefull shell commands

  • List directory:  ls [-la] [path]


Note: (“ls” == “dir” in Windows-cmd)

If you need more information about files/directories then add the parameter “-la”!

Example:

ls /system/libcp

 

  • change directory: cd [path]


Notes:
Absolute paths work everywhere, from every folder. They always start with “/”, which is the root (the start). On android, then you have some subfolders like “system”, “data” and “sdcard” (which is the sdcard).  An example of an absolute path would be /sdcard/videos (the folder videos on your sdcard)

Relative paths are relative to your position as the name would suggest.
If you currently are in the /sdcard folder, you can just switch to the videos directory by using the command: cd videos

 

  • Copy file or directory Syntax: cp [options] source dest


Note:
There are several commands for file operations. They will be explained in the next section. Please note that removing important system files may harm your system. If you’re not 100% sure, don’t try it before you are!

To copy or delete files in Android root directories you have to change the directory access mode to “read and write (rw)” [“read only (ro)”] using command: remount rw

Example_1: … this will copy bootanimation.zip from the sdcard to the folder where it is loaded at boot. It will overwrite the current bootanimation.zip in that folder.

remount rw /system
cp /sdcard/bootanimation.zip /system/media/
remount ro /system

Example_2: will replace the default android font with segoeui, and rename segoeui.ttf to DroidSans.ttf so Android recognises it.

remount rw /system
cp /sdcard/fonts/segoeui.ttf /system/fonts/DroidSans.ttf
remount ro /system

PS: you can also use e.g. “ES File Exporer” for copy & past files

 

  • displays the contents of a file or copy it: cat file


Example: show a file named lall.txt in /system/data/

cat /system/data/lall.txt

“or”

cd /system/data/
cat lall.txt

 

  • Move file or directory Syntax: mv [options] source dest


Example:

mv /system/lib/libsec-ril.so /sdcard/backupchmod

 

  • Change file/directory permission Syntax: chmod [-R] mode[,mode] …. file


Example:

chmod 0644 /system/lib/libsec-ril.sorm

Notes:
First you need to know how permissions work in Linux.
It works with 3-numbers: “xyz”

x – is what the owner can do
y – is the permission for the public user
z – is what other users can do (public = dangerous)

x,y and z can have different values:
7 full (read, write, execute)
6 read and write
5 read and execute
4 read only
3 write and execute
2 write only
1 execute only
0 none

 

  • Remove file or directory Syntax: rm [options] file


Example:

rm /system/lib/libsec-ril.so4. Install application

 

  • shows on the kernel debug info: dmesg


  • displays the running processes: ps


  • shows the system utilization: top


Note:
– press “P” and the output will be ordered by CPU-usage
– press “M” and the output will be ordered by Memory-usage

 

  • shows all mounted partitions: mount


  • grep is a filter and the “|” (pipe) allows to combine separate commands


Example: show only the system-mount

mount | grep system

 

  • You can also write output from a command to a file with “>”


Example_1: copy the output from Android-Debug to your SD-Card

logcat -f /sdcard/logcat.txt

Example_2: copy the output from Kernel-Debug to your SD-Card

dmesg > /sdcard/dmesg.txt

Example_3: change CPU-Governor to e.g. conservative

echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

Some usefull adb commands

 

  • Android will be re-launched

adb reboot

 

  • Android will be started in recovery mode

adb reboot recovery

 

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

adb install appname.apk

Example:

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

 

  • Copy files from phone to local drive

Syntax:
adb pull source [destination]

Example:

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

 

  • Copy files from local drive to phone

Syntax:
adb push source destination

Example:

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

 

  • a TCP port of Android directly connected to a TCP port of our operating system

Syntax:
adb forward tcp:[source-port] tcp:[destination-port]

Example:

adb forward tcp:5901 tcp:5901

sources:
http://s2tip.blogspot.de/2012/02/how-to-use-android-adb-command-line.html
http://forum.samdroid.net/f38/howto-android-debug-bridge-adb-4378/

PS: there are also good videos on youtube about “android adb” if you need some live examples 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*