Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

List available packages from one repository

last updated 2020-01-07

For dnf

dnf list available --disablerepo=* --enablerepo=reponame

For dpkg (low-level package manager for apt)

ff() { 
   for file in "/etc/apt/sources.list.d/${1}.list";
   do 
      for repo in $( awk '$1 ~ /^deb$/ {print $2}' "${file}" | sed -r -e 'sX\/X_Xg;' -e 's/\<https?.__//g;' ) ;
      do
         awk '$1 ~ /Package:/ {print $2}' /var/lib/apt/lists/${repo}Packages | sort | uniq
      done
   done;
}
ff reponame

The story

For some reason it is harder to manage packages with apt: This is a main reason I don't like to use it. I had to go write this crazy one-liner function to accomplish the same task that dnf provides with just two flags. Also, the apt command here shows all the packages from that repository, regardless of its installed state. The dnf command will show only the ones available that are not already installed.

Comments