adb shell opens a Linux shell in a target device or emulator.
It is the most powerful and versatile way to control an Android device via
This topic was split from ADB (Android Debug Bridge) due to reaching the limit of examples, many of which were involving
adb shell command.
- adb shell [-e escape] [-n] [-Tt] [-x] [command]
|-e||choose escape character, or "none"; default '~'|
|-n||don't read from stdin|
|-T||disable PTY allocation|
|-t||force PTY allocation|
|-x||disable remote exit codes and stdout/stderr separation|
Changing file permissions using chmod command
Notice, that in order to change file prmissions, your device need to be rooted,
su binary doesn't come with factory shipped devices!
Numeric permission constructed from user, group and world sections.
For example, if you want to change file to be readable, writable and executable by everyone, this will be your command:
if you intent to deny any permissions to it.
1st digit-specifies user permission, 2nd digit- specifies group permission, 3rd digit - specifies world (others) permission.
Generating a "Boot Complete" broadcast
This is relevant for apps that implement a
BootListener. Test your app by killing your app and then test with:
your.package/your.app.BootListener with proper values).
Granting & revoking API 23+ permissions
A one-liner that helps granting or revoking vulnerable permissions.
Granting all run-time permissions at a time on installation (-g)
kill a process inside an Android device
Sometimes Android's logcat is running infinitely with errors coming from some process not own by you, draining battery or just making it hard to debug your code.
A convenient way to fix the problem without restarting the device is to locate and kill the process causing the problem.
03-10 11:41:40.010 1550-1627/? E/SomeProcess: ....
notice the process number: 1550
Now we can open a shell and kill the process.
Note that we cannot kill
inside the shell we can check more about the process using
and kill it if we want:
Prints all packages, optionally only those whose package name contains the text in <FILTER>.
-f to see their associated file.
-i See the installer for the packages.
-u to also include uninstalled packages.
-u Also include uninstalled packages.
Attributes that filter:
-d for disabled packages.
-e for enabled packages.
-s for system packages.
-3 for third party packages.
--user <USER_ID> for a specific user space to query.
Open Developer Options
Will navigate your device/emulator to the
Developer Options section.
Print application data
This command print all relevant application data:
- version code
- version name
- granted permissions (Android API 23+)
Recording the display
Recording the display of devices running Android 4.4 (API level 19) and higher:
(press Ctrl-C to stop recording)
Download the file from the device:
Note: Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically at three minutes or the time limit set by
Sets the video size: 1280x720. The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder.
Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 5Mbps:
Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
Rotates the output 90 degrees. This feature is experimental.
Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running.
Note: This might not work on some devices.
The screen recording command isn't compatible with android versions pre 4.4
The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file.
Send text, key pressed and touch events to Android Device via ADB
execute the following command to insert the text into a view with a focus (if it supports text input)
Send text on SDK 23+
If already connected to your device via
Send text prior to SDK 23
Spaces are not accepted as the input, replace them with %s.
To simulate pressing the hardware power key
Even if you don't have a hardware key you still can use a
keyevent to perform the equivalent action
Send touch event as input
Send swipe event as input
*DURATION is optional, default=300ms. source
Get X and Y points by enabling pointer location in developer option.
ADB sample shell script
To run a script in Ubuntu, Create script.sh right click the file and add read/write permission and tick allow executing file as program.
Open terminal emulator and run the command ./script.sh
For a comprehensive list of event numbers
- shortlist of several interesting events ADB Shell Input Events
- reference documentation https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_POWER.
Set Date/Time via adb
Default SET format is
MMDDhhmm[[CC]YY][.ss], that's (2 digits each)
For example, to set July 17'th 10:10am, without changing the current year, type:
Tip 1: the date change will not be reflected immediately, and a noticable change will happen only after the system clock advances to the next minute.
You can force an update by attaching a
TIME_SET intent broadcast to your call, like that:
Tip 2: to synchronize Android's clock with your local machine:
Both tips together:
Default SET format is 'YYYYMMDD.HHmmss'
Tip: to synchronize Android's clock with your local (linux based) machine:
View external/secondary storage content