Score:3

Listing installed packages using apt list --installed, but only display the package names

mz flag

I use bash a lot and I was working on a script that I could use to help someone uninstall a package, and in the error message that shows when the package is not on the system, I am trying to figure out how to display a list of all installed packages, like apt list --installed does, but without all the information (for example: without /jammy,now 1.4.8+dfsg-3build1 amd64 [installed,automatic]), but just display the package names. Here is the command that I tried to display the packages without the extra info from my code:

apt list --installed | grep -oP '/jammy \K.*' |  grep -o "$removepackagename" | awk -F'|' 'NR==1 {print;x=$2} NR>1 {if ($2 != x) {print;x=$2}}'

I hoped that my command above would show me the list of packages that was installed without the extra info. Also, In the command above, I tried channeling my knowledge of grep (which is pretty much 0) to remove the extra info, and that part of the command is:

grep -oP '/jammy \K.*'

I also wanted the output to be something like:

apt
aptitude
(some other packages on new lines each)

(I also know that that is not what it actually will output, this is just a example.)

Cyrus avatar
cn flag
Please add your desired output to your question (no comment).
Score:3
sa flag

To list only the names of all installed packages:

apt list --installed | cut -d'/' -f1 | uniq

To list the names of all installed packages only one screen at a time to make it easier to scroll through the results:

apt list --installed | cut -d'/' -f1 | uniq | less

To save a list of the names of all installed packages in a file named installed-packages.txt

apt list --installed | cut -d'/' -f1 | uniq > installed-packages.txt
qwerty_coder avatar
mz flag
Thanks so much! I will use this in my project. For some reason I never thought to use awk!
karel avatar
sa flag
@Quasímodo Thanks for commenting. I edited my answer so that the output no longer includes those unwanted package architecture suffixes.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.