Appearance
adb shell: run commands on the phone
In short: adb shell opens a command line on a connected Android phone from your computer. Run adb shell to type commands on the phone, or adb shell followed by one command to run just that, such as adb shell pm list packages. Useful tools inside it include pm for apps, am for activities, input, getprop, settings and dumpsys.
Most of what adb can do beyond installing apps and copying files happens through the shell, so a handful of shell commands covers a lot of everyday testing work.
Syntax
bash
adb shell # an interactive command line on the phone; exit or Ctrl+D leaves it
adb shell <command> # runs one command and returns
adb -s R58M12345 shell <command>Quoting matters: adb shell pm list packages | grep google runs grep on your computer, while adb shell "pm list packages | grep google" runs the whole line on the phone.
Useful shell commands
| Command | What it does |
|---|---|
pm list packages -3 | Lists the apps you installed |
pm clear com.example.app | Clears an app's data, as Clear storage does |
pm grant com.example.app android.permission.CAMERA | Grants a runtime permission the app declares |
am start -n com.example.app/.MainActivity | Opens an activity |
monkey -p com.example.app -c android.intent.category.LAUNCHER 1 | Opens an app by its package name, as tapping its icon does |
am force-stop com.example.app | Stops an app at once |
am start -a android.intent.action.VIEW -d https://example.com | Opens a web address in the default browser |
input text hello%sworld | Types into the field that has focus (%s is a space) |
input tap 540 1200 | Taps a point on the screen, in pixels |
input swipe 540 1600 540 600 300 | Swipes from one point to another in 300 ms |
input keyevent KEYCODE_HOME | Presses a key: KEYCODE_BACK, KEYCODE_WAKEUP, KEYCODE_APP_SWITCH… |
getprop ro.product.model | The phone's model; ro.build.version.release is its Android version |
wm size | The screen's size in pixels |
dumpsys battery | Battery level, temperature and charging state |
svc power stayon usb | Keeps the screen on while the phone is charging over USB |
screencap and screenrecord | Screenshots and screen recordings, see adb screenshot |
Which commands exist, and their options, depend on the Android version. Most print their own help, for example adb shell pm help.
On many phones at once
bash
for s in $(adb devices | awk 'NR>1 && $2=="device" {print $1}'); do
echo "$s: $(adb -s "$s" shell getprop ro.build.version.release)"
donepowershell
adb devices | Select-Object -Skip 1 | ForEach-Object {
$serial, $state = $_ -split '\s+'
if ($state -eq 'device') { "${serial}: $(adb -s $serial shell getprop ro.build.version.release)" }
}That prints each phone's Android version. BenchFleet shows the same details, and the battery, temperature, storage and app in front, on every phone's tile, and gives each phone a terminal with restricted commands on its page.
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from £12 a month + VAT.
Common errors and fixes
| Error | What it means | Fix |
|---|---|---|
/system/bin/sh: … not found | That command does not exist on this phone's Android version | Check the spelling, or use the command's older name |
Permission denied | The shell user may not read or change that place | Use places such as /sdcard, or a rooted test phone |
adbd cannot run as root in production builds | adb root works only on emulators and development builds | Use the shell without root |
error: closed or device offline | The connection dropped | Reconnect; see adb devices |
adb: more than one device/emulator | Several phones are connected | Choose one with -s and its serial number |
Related
- adb logcat: read the log while your commands run.
- adb uninstall: find package names for
pmandam. - adb push and pull: copy files the shell works with.
- All ADB commands and the ADB command builder.
Questions
What is adb shell?
It is a command line on the phone, opened from your computer through ADB. Commands typed in it run on the phone with the rights of Android's shell user, which can manage apps, settings and input but not read other apps' private data.
How do I get out of adb shell?
Type exit and press Enter, or press Ctrl+D. If a command is still running, press Ctrl+C first.
Do I need root for adb shell?
No. adb shell works on any phone with USB debugging on. Root is needed only for protected places such as other apps' data in /data; adb root works on emulators and development builds, not on retail phones.
Why does a pipe in adb shell give different results?
Without quotes, the part after the pipe runs on your computer. Put the whole command in quotes, such as adb shell "pm list packages | grep google", to run it all on the phone.
Can I run adb shell commands on many phones at once?
Each command goes to one phone, so loop over adb devices with -s and each serial number, as shown on this page. BenchFleet gives every phone a terminal on its page and runs group actions on many phones on Pro.
Start with the Free plan
Free for up to 3 phones, with no account. Pro adds workflows, schedules and AI for up to 25 phones from £12 a month + VAT.
- A full refund within 14 days of your first payment
- Starts in Local mode, with no telemetry or analytics
- Made by WOODCOMMERCE LTD, a company registered in the UK