There is no formal definition of a metapackage. The informal definition is that a metapackage is one that is only intended to be installed for its dependencies and contains no useful file of its own.
You can define a metapackage as a package that contains no file. There is no way to determine this from the package database. You can use the file database and check that the package contains only directories (many such packages contain a few directories). In fact, most metapackages contain a few files in /usr/share/doc/<package name>
: a copyright
file, a changelog, sometimes a few more. Here's an approximation that defines a metapackage as containing only files in /usr/share/doc/<some directory>
(not in subdirectories of that) and the leading directories:
if ! apt-file -F list $package | grep -qvE '^/(usr(/share(/doc(/[^/]*(/[^/]*)?)?)?)?)?$'; then
echo "$package looks like a metapackage"
fi
Another approach is to look for a package tag with debtags
. There are several tags that are commonly used on metapackages.
debtags tag ls $package | grep -x -e 'role::metapackage' -e 'role::dummy' -e 'special::meta'
Another approach is to look for packages with a small size. Each directory counts as 4 kB, so plan accordingly when picking a threshold (again, this is an approximation).
aptitude -F '%I %p' search "~n^$package\$"
Upon reflection, I wonder if you mean virtual packages rather than metapackages. Virtual packages are actually not packages but package names used in Provides:
fields. You can list them with aptitude search '~v'
. Running apt-cache show
on one displays “Can't select versions from package 'zcav' as it is purely virtual”. Running aptitude show
lists the packages that provide it. A convenient way to show virtual packages is with apt-cache
: this prints one line for a non-virtual package and potentially multiple lines (one for each provider) for a virtual package — you can tell if the package is virtual even if there is a single provider because the name of the provider is different.
apt-cache -n search "^$package\$"
Since no answer using apt has been found, I would suggest going into Synaptic Package Manager, click on the Status button at lower left then click on Installed (manual) at upper left to see a list of installed packages.
Then you can output a list from Synaptic with File | Save Markings As
and save the file where you can work with it.
Best Answer
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:
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: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:~r
being?architecture()
which matches the architecture of the package andnative
which lists only the ones that have the same architecture as the system, the equivalent todpkg --print-architecture
.The previous line can therefore be written even more concisely as: