14

In Synaptic, one can list packages by section. For example, in the image below all packages of the "Amateur Radio (universe)" section are listed.

How can I get such a list (edit: with package description) at the command line?

I need a raw list; a terminal application like aptitude will not do.

synaptic

1
  • @bodhi.zazen that is a good suggestion, but does not search the Section only
    – Zombo
    Oct 31, 2014 at 5:11

4 Answers 4

11

Make sure the dctrl-toolsInstall dctrl-tools package is installed. It provides useful commands for searching the apt and dpkg package lists. To get a full description of all packages from a particular section that are installable with apt, run

grep-aptavail -F Section hamradio

This will show the full package metadata for every package in the hamradio section. If all you want to see are the package names, run

grep-aptavail -n -F Section -s Package hamradio

If your system is set up for multiarch, the same package may show up more than once in this listing if it is built for more than one architecture. So to refine this further, use either

grep-aptavail -n -F Section -s Package hamradio | sort | uniq

or

grep-aptavail -n -F Section -s Package hamradio | sort -u

to sort the package list and remove duplicate packages with the same name.

Note that you will have to use the actual name of the section, which is different from the "human-readable" name that Synaptic shows in its GUI. For example, the searches above use the section name hamradio instead of the string "Amateur Radio" shown in Synaptic.

See the man page for grep-aptavail for a full description of all options and some examples.

0
5

Well, though you say you don't want to use aptitude because of the output, you need to know that you can modify it to get what you like:

aptitude -F'|%p|%d|' search '?section(hamradio)'

The trick is in the -F switch that modifies the output format. %p means package. This also outputs when package has various architectures (ie amd64 vs i386), and %d which outputs the description. You can personalize the search pattern even more to for example not installed packages:

aptitude -F'|%p|%d|' search '?section(hamradio) !~i'

where ~i means installed and the ! is a not, so it reads as "not (!) installed (~i)", or if you only want the ones that are available to your architecture:

aptitude -F'|%p|%d|' search '?section(hamradio) ~r native'

~r being ?architecture() which matches the architecture of the package and native which lists only the ones that have the same architecture as the system, the equivalent to dpkg --print-architecture.

The previous line can therefore be written even more concisely as:

aptitude -F'|%p|%d|' search '~s hamradio ~r native'
9
  • Very elegant, especially with -F'|%p|%d|'. However, would it be possible not to list the :i386 packages by adding a !-expression to the search string? May 28, 2014 at 17:24
  • 1
    @GinGordon yeah, just add ~r native to the search terms. ~r being ?architecture which match the architecture of the package and native which list only the ones that has the same architecture than the system, the equivalent to dpkg --print-architecture. BTW, you wanted the list with package description?
    – Braiam
    May 28, 2014 at 17:35
  • Great! And yes, I have edited the question to include package description. Please, edit your answer accordingly and you deservingly will receive my best answer vote for being the most concise. May 28, 2014 at 17:53
  • @GinGordon check it out.
    – Braiam
    May 28, 2014 at 17:59
  • 1
    @GinGordon if you install the aptitude-doc package and navigate to /usr/share/doc/aptitude/html/en/index.html with your browser you will find in file:///usr/share/doc/aptitude/html/en/ch02s04s05.html all the nasty perks.
    – Braiam
    May 28, 2014 at 18:41
3

More fields on a single line, with arbitrary separator

The following one-liner will print all unique package names of a repository section, together with their description, each on a single line. All fields are separated by a pipe character, i.e. ready for conversion into a Markdown pipe table. The resulting table can be found on my web site.

grep-aptavail -n -s Package,Description -F Section hamradio |paste -sd '||\n' |sed 's:^:|:' |sort -u
3

You can use the following command to get a list of packages belonging to a given Section:

$ dpkg-query -W -f='${binary:Package} ${Section}\n' | awk '{if ($2 == "shells") {print $1}}'
bash
bash-completion
busybox-initramfs
busybox-static
dash
zsh
zsh-common

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .