adb-shell
Access Android device's command-line shell
TLDR
Start a remote interactive shell on the emulator or device
Get all the properties from emulator or device
Revert all runtime permissions to their default
Revoke a dangerous permission for an application
Trigger a key event
Clear the data of an application on an emulator or device
Start an activity on emulator or device
Start the home activity on an emulator or device
SYNOPSIS
adb [GLOBAL_OPTIONS] shell [COMMAND [ARGS...]]
PARAMETERS
COMMAND
Optional. The specific command string to execute on the Android device. If a command is provided, adb shell will execute it, print its standard output and error, and then exit. Multiple commands can be chained using standard shell operators (e.g., &&, ||, ;).
ARGS...
Optional. Arguments to be passed to the COMMAND being executed on the device. These arguments are interpreted by the shell environment on the Android device.
DESCRIPTION
The adb shell command is a crucial component of the Android Debug Bridge (ADB), a versatile command-line tool that allows communication with an Android-powered device or emulator. Specifically, adb shell provides a direct command-line interface (CLI) to the device's underlying Linux operating system. This functionality is invaluable for Android developers, system administrators, and power users for debugging applications, inspecting system state, managing files, and executing various system commands directly on the device. It can be used to execute a single command and return its output, or to establish a persistent, interactive shell session, much like SSHing into a remote Linux server. The commands available within the shell are typically standard Linux utilities, often provided by BusyBox or a more complete toybox environment, along with Android-specific tools like logcat, dumpsys, and am (Activity Manager).
CAVEATS
Connecting via adb shell requires debugging mode to be enabled on the Android device (typically found in Developer options > USB debugging).
Device authorization via a pop-up prompt might be required on the device's screen upon the first connection from a new host.
By default, permissions are often limited to the scope of a non-root user; accessing root capabilities typically requires a rooted device and the use of the su command within the shell.
The set of available commands and their behavior can vary slightly between Android versions and device manufacturers due to different BusyBox/toybox versions or custom system utilities.
Complex shell scripting or input/output redirection within a single non-interactive command can sometimes behave differently than on a full Linux system due to shell environment variations.
INTERACTIVE VS. NON-INTERACTIVE MODE
When no COMMAND is specified, adb shell enters an interactive mode, providing a continuous command prompt on the device, similar to a traditional terminal session. When a COMMAND is specified, it runs in non-interactive mode, executing the command, returning its output, and then returning control to the host shell after completion.
COMMON USES
adb shell is widely used for:
- Inspecting device logs (e.g., logcat)
- Managing packages (e.g., pm install/uninstall, pm list packages)
- Controlling services and activities (e.g., am start, dumpsys)
- Exploring and managing the device's file system (e.g., ls, cd, cp, rm, mkdir)
- Monitoring processes (e.g., ps, top)
- Capturing screenshots (e.g., screencap)
- Recording screen video (e.g., screenrecord)
ROOT ACCESS
On rooted devices, you can often gain root privileges within the adb shell by typing su. This provides elevated permissions, allowing access to protected system areas and execution of privileged commands, which is essential for advanced customization, deep debugging, and system modification.
HISTORY
The adb shell functionality has been a fundamental component of the Android SDK since its earliest versions, evolving alongside the Android operating system itself. Its development has closely mirrored the needs of app developers and system engineers, providing a critical interface for interacting with Android's Linux kernel and user space. Over time, security enhancements in Android have introduced new authorization steps for ADB connections, but the core utility of adb shell for development, debugging, and advanced system interaction has remained undiminished. It has consistently been the primary method for performing low-level operations on Android devices without requiring physical interaction or a graphical user interface.