34
votes
Accepted
What is this `adb` utility I keep getting advice to use?
About adb
To put it shortly, adb (Android Debug Bridge) is a utility made to be installed on a computer, in order to let it gain a shell on a phone that's either connected via USB cable, or on the ...
31
votes
How to find out currently running user name/ID from ADB
For Android 8, 9, 10, and possibly for Nougat too I suppose, run:
adb shell am get-current-user # returns USER_ID of the foreground user
adb shell cmd activity get-current-user # ...
19
votes
Enable location services via ADB or shell
On Android 6.0,
To enable:
GPS: adb shell settings put secure location_providers_allowed +gps
Network: adb shell settings put secure location_providers_allowed +network
To disable:
GPS: adb shell ...
16
votes
What's the best way to restart Android via command line (remotely)?
What is the device doing exactly when I'm pushing the (hardware) power button? I guess that's the most friendly way.
You get to see a dialog with an option to power off the device (stock Android ...
14
votes
Accepted
How to check if a package is enabled via shell?
pm list packages -d 2>/dev/null
will list up all disabled packages, one per line, preceded with the keyword package: – so output looks like
package:com.android.exchange
package:com.android.email
...

Izzy♦
- 90.6k
12
votes
Accepted
How to execute commands, after exiting ADB shell?
Write your script a little different:
#!/bin/bash
adb shell <<EOF
...
<open app menu>
<open app settings>
<save app backup>
...
EOF
adb pull /storage/emulated/0/Backups/ ~/...

Izzy♦
- 90.6k
11
votes
adb shell -> su: not found
Your device is not rooted. To see what Rooting is and how to go about doing it:
http://www.androidcentral.com/root
What does "to root a phone" mean?
Once you have rooted your device, you ...
8
votes
How to start root shell with Android Studio?
On a Mac Android Studio installs adb there:
/Users/<your username>/Library/Android/sdk/platform-tools
To use it in your shell, you can add it to your .profile file:
export PATH=/Users/<...
8
votes
Accepted
Activate USB tethering from the command line
If your Android version has svc inbuilt utility, run this command:
adb shell svc usb setFunctions rndis
This would enable USB tethering. To see what other USB functions are available, run:
adb shell ...
8
votes
Send a notification (or just vibrate) to phone via ADB/shell
Use cmd notification:
cmd notification post [flags] <tag> <text>
If you are root notification will not be displayed:
su -lp 2000 -c "cmd notification post -S bigtext -t 'Title' 'Tag' ...
8
votes
Accepted
Stock Android always using 100% physical memory. How to free it up with ADB?
Android memory management works differently than traditional OS. The main principle is to keep apps in RAM even if they are not used at the moment because the OS never knows when the user switches ...
7
votes
How can I run a script on boot?
If you have Magisk installed you can place the .sh to:
/sbin/.magisk/img/.core/service.d/
or to
/sbin/.magisk/img/.core/post-fs-data.d/
Don't forget to make it executable: chmod +x your-script.sh.
...
7
votes
Enable location services via ADB or shell
Android location service comes with different options:
High accuracy: gps, network
Enable: adb shell settings put secure location_providers_allowed +gps,network
Disable: adb shell settings put ...
7
votes
Accepted
How to kill dhcpcd?
A way to dynamically get the PID of the dhcp process, and kill it altogether, would be to run:
su
var=$(ps | grep dhcp)
kill $(echo -n $var | cut -d " " -f 0)
Specifically:
line 1 asks for root ...
6
votes
Is it possible to set device's Latitude and Longitude using ADB SHELL?
Alternatively what might also be an option here is to use Appium's io.appium.setting's app.
Once that app's installed on the device you can give it permissions and mock location through adb like ...
6
votes
Accepted
How do I install missing command line tools onto an Android device?
For rooted Android devices
You can consider installing BusyBox app by Stephen. Per Play Store, the minimum Android version supported by app is Android 1.6 and it is a well-updated app. In essence, it ...
6
votes
Accepted
Run downloaded shell command without root?
Yes, this is by design. You can't execute binaries from the SD card without system or superuser privileges (and remounting it without the noexec option) because otherwise apps could just download and ...
6
votes
adb shell error: device not found (Ubuntu)
Check adb devices. If no device shows up follow the steps below.
First, check to make sure USB Debugging is enabled. On most devices:
Go into 'About Phone', 'About Device', or 'About Tablet'
Find '...
6
votes
Accepted
Where can I run a .sh script on Android without root?
/storage/emulated/0 is usually mounted in a way that prevents execution of programs from this location.
Therefore even with a set executable bit for your script you won't be able to execute it ...
6
votes
Send a notification (or just vibrate) to phone via ADB/shell
You can setup a Task in Tasker which you can invoke from command-line. The task can be setup with actions of your liking in combination, such as show a notification and vibrate with XYZ pattern. When ...
6
votes
Accepted
List devices/computers that have been authorized for ADB USB Debugging
You can see which devices were authorized by you on your phone to interact with it through adb. You would need root access though.
Go into the directory /data/misc/adb/. There would be two files:
...
5
votes
Run downloaded shell command without root?
Android, just as Linux, prevents any user but root, to change the permission bits of any file not owned by such user. That said, chmod is ineffective, unless you have root privileges.
By the way, ...
5
votes
Is there a non-app tool for batch backup of APK files?
This script is outdated and no longer supported. For the newest version, which requires Android 5+ and Python 3.5+, and supports Arcus theme variants and Substratum overlays, see my GitHub repository.
...
5
votes
__bionic_open_tzdata_path: ANDROID_DATA not set!
For ssh users, following up on @Death Mask Salesman's comment. sshd allows setting up ENV via proper config (from man --pager='less -p ^ENVIRONMENT' ssh):
[...] Additionally, ssh reads ~/.ssh/...
5
votes
Using LineageOS native SSHD over ADB
AFAIK with LineageOS 14.1 (I have a rooted FairPhone 2), sshd is enabled by default and ready to use. Its config file is /system/etc/ssh/sshd_config which points to /data/ssh/ for keys storage. I ...
5
votes
How can I see all installed packages, including those that have been hidden?
If you run adb shell pm you would find many options and parameters for pm. One of the parameter is -u to show uninstalled packages. (Hidden packages are treated as uninstalled packages.)
On an ...
5
votes
How to set static IP on command line or adb shell?
You can try using ip command.
How it compares to ifconfig
Edit:
To set up an IP address you can use:
ip address add 192.168.0.77 dev eth0
or the long form
ip addr add 192.168.0.77/24 ...
5
votes
Accepted
How to screencap the smaller display of Samsung Galaxy Fold using ADB 'screencap' command?
The screencap command can be configured to capture a specific display using the option -d.
-d: specify the physical display ID to capture.
See dumpsys SurfaceFlinger --display-id for valid ...
5
votes
Accepted
Android stops/pauses execution of my background script?
Android turns off some of CPUs and/or don't let apps use them when it's dozing. It's achieved through Linux kernel's Control Groups. One of the cgroups is cpuset that controls which CPU is assigned to ...
5
votes
Accepted
Is there a way to call/invoke a (private) Java function in an app?
Rooted device
On rooted devices private function in apps can be called quite easily (in most cases) using a tool like Frida. Frida is like a mixture of a "scriptable debugger" and Xposed ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
shell × 406adb × 186
root-access × 43
command-line × 39
terminal × 36
scripts × 29
linux × 23
bash × 16
mount × 15
networking × 14
file-system × 13
busybox × 12
permissions × 11
applications × 10
rooting × 10
settings × 10
android-emulator × 10
ssh × 10
recovery-mode × 9
file-permissions × 9
5.0-lollipop × 8
usb × 8
tasker × 8
termux × 8
cyanogenmod × 7