Introduction
Recently, I bought a brand new Sony Xperia mainly because of its 24-bit DAC so I could listen to my HiRes FLAC files. It was the cheapest non-chinese vendor with dual SIM support that supports HiRes audio (wired/wireless).
Not a novel solution but more elegant!
The problem started as I noted that my phone has Netflix and Facebook pre-installed but there is no way to remove them using the standard Android GUI. A quick search led me to this post by xda developers which solved my problem. In short the solution is fairly straightforward:
- Install ADB and enable USB debugging
- Connect to your device through ADB shell
- Search for package names that you want to remove
- Use
pm uninstall
to remove packages one by one
I thought to myself “well if we are using a simple shell, we could put the last two steps together and get rid of copy/pasting”. So this is the result:
pm list packages | grep facebook | sed 's/package://' | xargs -n 1 pm uninstall --user 0
pm
stands for package manager and is used here tolist
all installed packages and consequentlyuninstall
bloatware.grep
is used to filter only desired packages (herefacebook
).sed
is to cleanup results.pm list
printspackage:
string as prefix for each package name.xargs
takes the results from previous commands and apply them as arguments to the given command (herepm uninstall --user 0
). Note the usage of-n 1
that tellsxargs
to executepm uninstall
for each line of result not once for all results.
One last note: later, I found out that someone had already proposed a similar solution but using td
instead of sed
.