Skip to content

Instantly share code, notes, and snippets.

@gchait
Last active December 15, 2025 21:12
Show Gist options
  • Select an option

  • Save gchait/61346cea871861a3d537d063e469438b to your computer and use it in GitHub Desktop.

Select an option

Save gchait/61346cea871861a3d537d063e469438b to your computer and use it in GitHub Desktop.
Debloat matching packages via ADB without root
#!/bin/bash -eu
set -o pipefail
readonly USER_ID=0
list_packages() {
local flags="${1:-}"
local cmd=(adb shell cmd package list packages --user "${USER_ID}")
[[ -n "${flags}" ]] && cmd+=("${flags}")
"${cmd[@]}" | cut -d: -f2
}
filter_packages() {
grep -i -E "${1}" || true
}
remove_package() {
local pkg="${1}"
echo "Processing ${pkg}..."
adb shell cmd package uninstall --user "${USER_ID}" "${pkg}" ||
adb shell pm disable-user --user "${USER_ID}" "${pkg}"
}
show_filtered_packages() {
local label="${1}" pattern="${2}" flags="${3:-}"
echo "${label}:"
list_packages "${flags}" | filter_packages "${pattern}"
}
die() {
echo "${1}"
exit 0
}
main() {
read -rp "Enter package keyword(s) to search for (e.g., chrome bixby): " keywords
[[ -z "${keywords}" ]] && die "No keywords entered. Exiting."
local pattern="${keywords// /|}"
local packages
packages=$(list_packages | filter_packages "${pattern}")
[[ -z "${packages}" ]] && die "No packages found matching: ${keywords}"
echo "Found the following packages:"
echo "${packages}"
echo
read -rp "Do you want to remove/disable all these packages? [yes/no]: " confirm
[[ "${confirm}" != "yes" ]] && die "Aborted by user."
local pkg
while IFS= read -r pkg; do
[[ -n "${pkg}" ]] && remove_package "${pkg}"
done <<< "${packages}"
echo
echo "Done."
echo
show_filtered_packages "Disabled packages" "${pattern}" "-d"
echo
show_filtered_packages "Remaining packages" "${pattern}"
}
main "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment