This article introduces the commonly used adb ssh commands. You can execute adb commands in the following two ways:
Downloading files can be time-consuming. By appending
> /dev/null 2>&1 &
to the command, you can execute the command in the background.
wget --no-check-certificate -O /sdcard/test.apk https://YOUR_APK_URL/test.apk > /dev/null 2>&1 &
Uploading files can be time-consuming. By appending > /sdcard/upload.log
to the command, you can write the upload progress to a log file; by appending 2>&1 &
to the command, you can execute the command in the background to avoid command execution timeout.
curl -F "file=@/sdcard/test.apk" https://temp.sh/upload > /sdcard/upload.log 2>&1 &
After the upload is complete, use the following command to check the upload progress. If the upload is successful, you will see the file download URL in the log file:
cat /sdcard/upload.log
# Usage
adb push [local computer file location] [cloud device file location]
# Example
adb push C:\Users\YourUsername\Documents\example.txt /sdcard/example.txt
# Usage
adb pull [cloud device file location] [local computer file location]
# Example
adb pull /sdcard/example.txt C:\Users\YourUsername\Documents\
adb exec-out screencap -p > screenshot.png
pm list packages -3 | cut -d ":" -f 2
pm install /sdcard/test.apk
am start -n $(dumpsys package [package_name] | grep -A 1 'MAIN' | grep '[package_name]' | sed -n 's/.*\(package_name\/[^ ]*\).*/\1/p')
am force-stop [package_name]
pm uninstall [package_name]
pm clear [package_name]
List of permission names: https://developer.android.com/reference/android/Manifest.permission#summary
pm grant [package_name] android.permission.[permission_name]
logcat -c
cat logcat | nc termbin.com 9999
The returned content will include a URL containing the logcat log content.
Tip: This command can upload any text content. For example:
cat /sdcard/test.txt | nc termbin.com 9999
You can simulate key operations by calling input keyevent [code]
.
Below are some commonly used KeyEvent codes for reference:
KeyEvent Code | Corresponding Key | Description |
---|---|---|
4 | Back Key (BACK) | Simulate pressing the back button |
19 | Up Arrow Key (DPAD_UP) | Simulate pressing the up arrow key |
20 | Down Arrow Key (DPAD_DOWN) | Simulate pressing the down arrow key |
21 | Left Arrow Key (DPAD_LEFT) | Simulate pressing the left arrow key |
23 | Select Key (DPAD_CENTER) | Simulate pressing the select key (similar to confirming a click) |
82 | Menu Key (MENU) | Open the device's menu options |
24 | Volume Up Key (KEYCODE_VOLUME_UP) | Simulate increasing the device's volume |
25 | Volume Down Key (KEYCODE_VOLUME_DOWN) | Simulate decreasing the device's volume |
Usage Examples
input keyevent 19 # Up Arrow Key
input keyevent 66 # Enter Key
input keyevent 3 # Home Key
# Click at coordinates (500,300)
input tap 500 300
# Click at coordinates (500,300) and hold for 200ms
input swipe 500 300 500 300 200
# Swipe from coordinates (500,500) to (500,100) over a total duration of 200ms (i.e., swipe up by 400)
input swipe 500 500 500 100 200