Generate a root debloat script from a package list after a successful non-root debloat There are two ways to get rid of apps to debloat a ROM:

adb shell pm uninstall -k --user 0  (run on PC)
rm -rf  (on device, in Terminal of TWRP)

The first method has one big advantage - deleted apps can be restored by

adb shell cmd package install-existing &lt;package_name&gt;
But the diasadvantage - it still consumes memory.

So best would be to do the first method until you see is is all fine - not debloated to much. To not manually do the &quot;rm&quot; and selection of packages - is there a good way to list the uninstalled packages and generate a list for the &quot;rm&quot; command?
Thanks for your attention.
I guess you mean only uninstalled system packages.
Here is a little bash script doing what you want:
#!/usr/bin/env bash

set -euo pipefail

declare -a PACKAGES=()

readarray -t PACKAGES &lt; &lt;(comm -3 &lt;(adb shell 'pm list packages -s -u -f' | sort -i) \
                                  &lt;(adb shell 'pm list packages -s -f'    | sort -i))

for package in &quot;${PACKAGES[@]}&quot;; do
    echo &quot;rm -rf $package&quot; | sed -r 's/package://g' | sed -r 's/=.*//g' &gt;&gt; root_debloat.txt
done
echo &quot;root_debloat.txt generated.&quot;

Then, you just need to run the commands through adb shell as root:
adb shell su &lt; root_debloat.txt


What the script does :

Put the list of uninstalled system packages in the array PACKAGES.

Why this complicated command ? Because pm list packages -s -u returns installed and uninstalled system packages. So you need to take the difference of this list and the list of installed system packages.
Each element of the array will have this form (because of the use of the -f option) :
package:/path/to/apk=package.name

Generate the list of rm commands and write them one by one, for each package, in the root_debloat.txt file.

You only want the path. The sed commands are here to remove the rest.