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"
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\$"