Skip to content

Published

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 ​

CommandWhat it does
pm list packages -3Lists the apps you installed
pm clear com.example.appClears an app's data, as Clear storage does
pm grant com.example.app android.permission.CAMERAGrants a runtime permission the app declares
am start -n com.example.app/.MainActivityOpens an activity
monkey -p com.example.app -c android.intent.category.LAUNCHER 1Opens an app by its package name, as tapping its icon does
am force-stop com.example.appStops an app at once
am start -a android.intent.action.VIEW -d https://example.comOpens a web address in the default browser
input text hello%sworldTypes into the field that has focus (%s is a space)
input tap 540 1200Taps a point on the screen, in pixels
input swipe 540 1600 540 600 300Swipes from one point to another in 300 ms
input keyevent KEYCODE_HOMEPresses a key: KEYCODE_BACK, KEYCODE_WAKEUP, KEYCODE_APP_SWITCH…
getprop ro.product.modelThe phone's model; ro.build.version.release is its Android version
wm sizeThe screen's size in pixels
dumpsys batteryBattery level, temperature and charging state
svc power stayon usbKeeps the screen on while the phone is charging over USB
screencap and screenrecordScreenshots 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)"
done
powershell
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 ​

ErrorWhat it meansFix
/system/bin/sh: … not foundThat command does not exist on this phone's Android versionCheck the spelling, or use the command's older name
Permission deniedThe shell user may not read or change that placeUse places such as /sdcard, or a rooted test phone
adbd cannot run as root in production buildsadb root works only on emulators and development buildsUse the shell without root
error: closed or device offlineThe connection droppedReconnect; see adb devices
adb: more than one device/emulatorSeveral phones are connectedChoose one with -s and its serial number

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.