Mastering ADB: Complete List of Shell Commands
ADB shell commands provide a powerful bridge between your development machine and an Android device, unlocking deep system control and automation possibilities. This reference guide serves as a definitive resource for understanding the full spectrum of commands available through the Android Debug Bridge shell environment.
Whether you are a seasoned developer, a power user, or someone exploring advanced device management, mastering these instructions allows you to inspect logs, modify system settings, manage files, and troubleshoot issues that are otherwise inaccessible through the standard user interface. The following breakdown categorizes these instructions for clarity and practical application.
Device Interaction and Management
The foundation of working with ADB lies in managing the connection and state of your Android device. These instructions allow you to verify connectivity, view essential hardware information, and control the device lifecycle directly from your command line. Understanding these is the first step before diving into more complex system-level operations.
By utilizing these core instructions, you can ensure your development environment is correctly linked to the target device, which is crucial for deploying applications, pulling logs, or executing any file transfer operations. Proper device management prevents many common errors encountered during debugging and testing phases.
Device State and Identification
To verify that your device is properly connected and recognized, you can query its current status. The command to list all attached devices displays serial numbers and connection states, which is essential when multiple devices are connected. This ensures you are sending commands to the correct target.
Furthermore, you can retrieve detailed information about the device's software and hardware, such as the model number, Android version, and security patch level. This contextual information is vital for debugging compatibility issues and confirming that the device meets the requirements for specific tests or installations.
Installation and Uninstallation
Managing applications directly from the command line is significantly faster than using the GUI, especially for beta testing or scripting repetitive tasks. You can install APK files silently, replacing existing versions without manual confirmation. This is particularly useful for continuous integration pipelines.
Conversely, removing applications can also be handled via these instructions, allowing for the cleanup of test apps or bloatware. You have the option to remove only the base package or to include and delete associated user data and cache directories, ensuring a clean slate upon reinstallation.
File System Operations
Navigating and manipulating the file system of an Android device is one of the most versatile capabilities offered by the shell. These instructions mirror traditional Linux commands, allowing you to copy, move, delete, and examine files with precision. This section details the most commonly used file management instructions.
Understanding the directory structure of Android is key to effective file manipulation. Unlike a standard computer, the file system is divided into partitions such as system, data, and cache, each with specific permissions. Using these instructions correctly ensures you can access necessary logs or media without disrupting system integrity.
Navigation and Listing
The `ls` instruction lists the contents of a directory, providing details like permissions, ownership, and file size. By combining this with specific paths, you can quickly see what files are present in directories like `/sdcard/Download` or `/system/framework`.
The `cd` instruction allows you to change your current working directory. Mastering path navigation is essential to reach deeper folders where application data or configuration files are stored, enabling you to perform detailed inspections or backups.
File Transfer and Modification
To move a file from your computer to the device, you use the `push` instruction, which copies files or directories to a specified location on the device. Conversely, the `pull` instruction extracts files from the device to your computer, which is useful for backing up game saves or application databases.
For editing text-based files such as configuration scripts or property files, you can invoke standard Linux text editors like `vi` or `nano` through the shell. This allows for on-device modification of hosts files or system properties without the need to create complex scripts for simple changes.
System Debugging and Log Analysis
Diagnosing issues requires access to the system logs and the ability to monitor real-time processes. These instructions provide a window into the operating system's inner workings, revealing errors, warnings, and informational messages that are critical for troubleshooting crashes or performance bottlenecks.
By filtering and analyzing this data, developers can identify the root cause of application failures or system instability. The ability to clear logs or monitor them live makes the debugging process significantly more efficient and targeted.
Logcat and Runtime Monitoring
The `logcat` instruction is an indispensable tool for developers, capturing the system and application logs in real time. You can filter these logs by tag, priority, or specific application package names to isolate relevant events. This helps in identifying crashes, warnings, or unexpected behavior as they occur.
Additionally, the `dumpsys` instruction provides a comprehensive overview of the system's current state. By specifying a service name, such as `activity` or `battery`, you can retrieve detailed diagnostic information about running processes, memory usage, and system health metrics.
Performance and Input Simulation
Monitoring system performance is possible through instructions that provide CPU usage and memory statistics. The `top` instruction offers a real-time view of processes consuming the most resources, which is useful for identifying performance bottlenecks or memory leaks in applications.
For testing user interactions, you can simulate input events directly from the command line. Instructions for sending key events or tapping on specific coordinates allow for the automation of UI testing or navigating through menus without physically touching the screen.
Advanced System Control
For advanced users and developers, ADB shell provides the ability to modify system properties and settings that are normally hidden from the user interface. This level of control allows for deep customization and testing of device behavior, but it requires caution as incorrect changes can affect system stability.
These instructions interact with the underlying property system of the Android operating system. Reading and writing these values can tweak animations, enable hidden features, or adjust security parameters, offering a level of granular control that is not available in the standard settings menu.
Property System Management
The `getprop` instruction allows you to view the value of a specific system property, such as the device brand or build type. This is useful for verifying configuration details or ensuring that a device is in the correct state for testing.
Conversely, the `setprop` instruction allows you to change the value of a property temporarily. While this does not persist after a reboot unless handled by an init script, it is extremely useful for testing how applications behave under different system configurations or languages.
Reboot and System Operations
Controlling the device power state is straightforward with the `reboot` instruction. You can reboot the device normally, or into specific modes such as the bootloader or recovery partition. This is essential for flashing custom ROMs or performing advanced maintenance tasks.
For security and maintenance, the `pm` (package manager) instruction allows for deeper control over applications, such as clearing their cache or data. This is often necessary when an app behaves erratically and a simple force stop is insufficient to resolve the issue.
Mastering this collection of ADB shell instructions empowers you to take full control of your Android device, transforming it from a simple consumer gadget into a highly configurable tool. As you become more familiar with these commands, you will find new ways to optimize your workflow, solve complex problems, and interact with your technology on a much deeper level.