Table of Contents
Android has turned out to be the most popular open source operating system for mobile phones. The OS can be customized, modified or even personalized in numerous different ways. Gaining root access has become quite common with Android due to the various privileges that come with it. However, in order to get into Android development, you need to get familiar with ADB and Fastboot commands. So here are the most useful ADB and fastboot commands for you.
ADB, which stands for Android debugging, can be used to issue a set of array commands to your Android device through a terminal or cmd. ADB commands can perform operations like a reboot, sideload OTA updates, install APK files, or even extract system apps.
Fastboot commands can be issued via bootloader or fastboot menu to flash firmware files or custom recoveries. Most common use it to unlock the bootloader of your Android device. These commands can be issued via command prompt or terminal using a Windows PC, Mac or Linux machine.
Warning: If you are not sure about any command, you should refrain from using it. Some of the changes may not be restored. So be cautious.
Most commonly used ADB commands
- adb devices – list all connected devices
- adb reboot – perform a reboot
- adb reboot bootloader – reboot into bootloader or fastboot menu
- adb reboot recovery – reboots into recovery [stock or TWRP whichever is installed]
- adb reboot download – reboots the device into download mode (if available, mainly for LG)
- adb reboot sideload – reboots the device into sideloading menu
- adb sideload – used to sideload or install OTA updates
For instance-
adb sideload ota.zip
adb install – used to install files and applications on Android
For instance- install and apk file
adb install OPFilemanager.apk
While updating and app use the -r switch
adb install -r OPFilemanager.apk
adb uninstall – used to uninstall APK
For instance-
adb uninstall .apk
adb push – copy file/dir to device
For instance-
adb push OPFilemanager.apk sdcard/
adb logcat – get the full logcat or Android ROM
adb logcat > filename.txt
adb pull [] – copy file/dir from device
For example-
adb pull /system/reserve/OPFilemanager/OPFilemanager.apk
List of all ADB commands:
adb devices – list all connected devices
adb push – copy file/dir to device
adb pull [] – copy file/dir from device
adb sync [ ] – copy host->device only if changed
(-l means list but don’t copy)
(see ‘adb help all’)
adb shell – run remote shell interactively
adb shell – run remote shell command
adb emu – run emulator console command
adb logcat [ ] – View device log
adb forward – forward socket connections forward specs are one of: tcp:
localabstract:
localreserved:
localfilesystem:
dev:
jdwp: (remote only)
adb jdwp – list PIDs of processes hosting a JDWP transport
adb install [-l] [-r] [-s] – push this package file to the device and install it
(‘-l’ means forward-lock the app)
(‘-r’ means reinstall the app, keeping its data)
(‘-s’ means install on SD card instead of internal storage)
adb uninstall [-k] – remove this app package from the device
(‘-k’ means keep the data and cache directories)
adb bugreport – return all information from the device
that should be included in a bug report.
adb help – show this help message
adb version – show version num
DATAOPTS: risk factor involved
(no option) – don’t touch the data partition
-w – wipe the data partition
-d – flash the data partition
Scripting: risk factor involved
adb wait-for-device – block until device is online
adb start-server – ensure that there is a server running
adb kill-server – kill the server if it is running
adb get-state – prints: offline | bootloader | device
adb get-serialno – prints:
adb status-window – continuously print device status for a specified device
adb remount – remounts the /system partition on the device read-write
adb reboot [bootloader|recovery] – reboots the device, optionally into the bootloader or recovery program
adb reboot-bootloader – reboots the device into the bootloader
adb root – restarts the adbd daemon with root permissions
adb usb – restarts the adbd daemon listening on USB
adb tcpip – restarts the adbd daemon listening on TCP on the specified port
networking: risk factor involved
adb ppp [parameters] – Run PPP over USB.
Note: you should not automatically start a PPP connection.
< tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] – Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ ]
< localdir> can be interpreted in several ways:
– If is not specified, both /system and /data partitions will be updated.
– If it is “system” or “data”, only the corresponding partition is updated.
Most commonly used Fastboot commands
Fastboot commands will only work in bootloader or fastboot menu. Issue the following command to reboot into fastboot or bootloader menu.
adb reboot bootloader
OR
adb reboot fastboot
OR
adb reboot-bootloader
- fastboot devices – lists connected Android devices accessible via fastboot
- fastboot oem device-info – provides bootloader information (locked or unlocked)
- fastboot erase system – wipe/erase system
- fastboot erase data – wipe/erase data
- fastboot erase cache – wipe/erase cache
- fastboot flash
- fastboot flash recovery – flash recovery image
- fastboot flash boot – flash boot image
- fastboot flash system – flash system image
- fastboot flash data – flash data image
- fastboot flash cache – flash cache image
- fastboot flash userdata – flash userdata image
- fastboot flash bootloader – flash bootloader image
- fastboot flash radio – flash radio image
- fastboot help
List of all fastboot commands
Usage: fastboot [ ]
commands:
update reflash device from update.zip
flashall flash boot + recovery + system
flash [ ] write a file to a flash partition
erase erase a flash partition
getvar display a bootloader variable
boot [ ] download and boot kernel
flash:raw boot [ ] create bootimage and flash it
devices list all connected devices
reboot reboot device normally
reboot-bootloader reboot device into bootloader
options:
-w erase userdata and cache
-s specify device serial number
-p specify product name
-c override kernel commandline
-i specify a custom USB vendor id
-b specify a custom kernel base address
-n specify the nand page size. default: 2048
How to setup and issue ADB or Fastboot commands via terminal?
The above commands won’t work for Android unless ADB or Fastboot environment is setup on the personal computer. We have already listed a quicker and easier method to setup ADB and Fastboot on Windows, Mac OS, Linux, and Chrome OS.
Prerequisites
- Enable USB Debugging on your device. To do so, go to Settings>About Phone> Tap on the Build Number several times until you get a new Developer Options in the Settings. Open Developer Options and enable USB Debugging from there. Trust the connection by allowing it when you connect it to your PC for the first time.
- Make sure you have ADB and Fastboot environment setup on Windows, Mac OS, Linux or Chrome OS. You may also like Universal ADB drivers, Naked ADB drivers.
- Make sure you have latest device drivers setup on your PC for a better connection. Get it from the official page of your device manufacturer.
Instructions to use ADB and Fastboot commands
Step 1: Go through the prerequisites. Now, connect your Android device to the PC and trust the connection- tap Yes on “Always allow from this computer” when you plug in the device into PC for the first time.
Step 2: Now launch a command prompt or terminal window anywhere. To do so, just click the address bar and type cmd and press Enter key or hold the shift key on the keyboard and right-click on an empty space and select “Open command window here” option to launch a cmd window.
Note: If you have installed the quick ADB installer, it will setup the ADB and Fastboot everywhere on your PC. If you use the minimal ADB package, then navigate to the location where you have setup ADB and Fastboot and launch a command prompt or terminal window there.
Step 3: Now here’s a trick. ADB and Fastboot work in different environments. For ADB commands to work, your devices need to be booted into the system and connected with USB debugging. For Fastboot commands to work, your device must be booted into bootloader or fastboot menu. (You can reboot into bootloader by issuing the following command)