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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.