Skip to content

Instantly share code, notes, and snippets.

@p32929
Created December 18, 2025 21:54
Show Gist options
  • Select an option

  • Save p32929/f16252fd4c838516b9d83601f7f3afc4 to your computer and use it in GitHub Desktop.

Select an option

Save p32929/f16252fd4c838516b9d83601f7f3afc4 to your computer and use it in GitHub Desktop.
remove all the user installed apps
#!/bin/bash
# Script to remove all user-installed apps from an Android device via ADB
# Author: Generated for Thrive project
# Usage: ./remove_android_apps.sh
echo "=================================="
echo "Android User Apps Removal Tool"
echo "=================================="
echo ""
# Check if adb is installed
if ! command -v adb &> /dev/null; then
echo "ERROR: adb command not found!"
echo "Please install Android Debug Bridge (ADB) first."
exit 1
fi
# Get list of connected devices
echo "Scanning for connected ADB devices..."
devices=$(adb devices | grep -v "List of devices" | grep "device$" | awk '{print $1}')
if [ -z "$devices" ]; then
echo "ERROR: No ADB devices found!"
echo "Please connect a device and enable USB debugging."
exit 1
fi
# Display devices and let user choose
echo ""
echo "Available devices:"
echo ""
device_array=()
counter=1
while IFS= read -r device; do
device_array+=("$device")
echo " [$counter] $device"
counter=$((counter + 1))
done <<< "$devices"
echo ""
read -p "Choose a device (enter number): " choice
# Validate choice
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt "${#device_array[@]}" ]; then
echo "ERROR: Invalid choice!"
exit 1
fi
selected_device="${device_array[$((choice - 1))]}"
echo ""
echo "Selected device: $selected_device"
echo ""
# Get list of user-installed packages (3rd party apps)
echo "Fetching list of user-installed apps..."
# Create temp file to store packages
temp_file=$(mktemp)
adb -s "$selected_device" shell pm list packages -3 | sed 's/package://' | tr -d '\r' > "$temp_file"
# Read into array
package_array=()
while IFS= read -r line; do
if [ -n "$line" ]; then
package_array+=("$line")
fi
done < "$temp_file"
# Clean up temp file
rm -f "$temp_file"
if [ ${#package_array[@]} -eq 0 ]; then
echo "No user-installed apps found on this device."
exit 0
fi
# Count packages
package_count=${#package_array[@]}
echo "Found $package_count user-installed app(s):"
echo ""
for pkg in "${package_array[@]}"; do
echo "$pkg"
done
echo ""
# Confirmation prompt
read -p "⚠️ WARNING: This will uninstall ALL $package_count user apps! Continue? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo "Operation cancelled."
exit 0
fi
echo ""
echo "Starting removal process..."
echo "Press Ctrl+C to stop at any time."
echo ""
sleep 2
# Remove each package
current=0
for package in "${package_array[@]}"; do
if [ -z "$package" ]; then
continue
fi
current=$((current + 1))
echo "[$current/$package_count] Removing: $package"
result=$(adb -s "$selected_device" shell pm uninstall --user 0 "$package" 2>&1)
if echo "$result" | grep -q "Success"; then
echo " ✓ Successfully removed"
else
echo " ✗ Failed: $result"
fi
echo ""
done
echo "=================================="
echo "Removal process completed!"
echo "Successfully processed $package_count app(s)."
echo "=================================="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment