4

I am using Ubuntu-15.10. I have installed many applications apart from vanilla installations.

Now, I would like to find out how many installed packages are licensed under the GPL or third-party licenses (e.g. Fluendo).

Is there any way to find this out? Or do I need to check manually each and every license of each installed application?

EDIT:

Following snippet I used to list out the name of various installed License files.

find /usr/share/doc -type f -name copyright -exec grep "License\:" {} + | cut -f3 -d: | sort -u
4

Packages' licenses are described in /usr/share/doc/${package}/copyright. This file is required to specify the main license of the package; many packages use a machine-readable copyright file which lists the licenses of every single file in the source package.

For machine-readable files, you can use the License: line which introduces licenses:

awk '/^License:/ { print $2 }' /usr/share/doc/*/copyright | sort -u

If you're looking for a license documented in /usr/share/common-licenses, you can look for mentions of those in the copyright files; e.g. to count the number of packages licensed under the GPL or LGPL:

grep -l GPL /usr/share/doc/*/copyright | wc -l

To only count the number of source packages, count the number of unique files (binary packages shipped from a single source package have the exact same copyright file, or link to the same file):

md5sum $(grep -l GPL /usr/share/doc/*/copyright) | sort -k1,1 -u | wc -l

Debsources provides various ways of searching through all of Debian's copyright files; here's a one-liner to retrieve the license of a single file (if its package uses a machine-readable format). (The license of that one-liner isn't documented, so I'm just linking to it, not copying it here.)

Note that since the copyright files document the licenses of the source packages, they may well document files which aren't shipped in binary packages and don't affect the license of the binary package; this can be the case for example with GPL-licensed files which are only used during the build for a non-GPL-licensed package.

3

Most of software's licensing information is available at /usr/share/doc/pkg-name/copyright

Roughly you can estimate the number of program using GPL by means of:

  • grep -l GPL /usr/share/doc/*/copyright

    But grep will also include files that are link instead of regular file. So, I recommend usinf find as follows:

  • sudo find /usr/share/doc -name copyright -type f -exec grep -l "GPL" '{}' \; | wc -l

    It will also include file(s) like /usr/share/doc/ca-certificates/examples/ca-certificates-local/debian/copyright, If you don't want them in counting, you can specify maxdepth with find.

Example (on my system):

$ grep -l GPL /usr/share/doc/*/copyright | wc -l
1949

$ sudo find /usr/share/doc -name copyright -type f -exec grep -l "GPL" '{}' \; | wc -l
1889

Note that a software may include more than one license per files in copyright.

1

Following code will help me list out the installed licenses from various application on Ubuntu 15.04.

find /usr/share/doc -type f -name copyright -exec grep "License\:" {} + | cut -f3 -d: | sort -u
  • This will only work for machine-readable copyright files; copyright files are still allowed to be free-form so there's no guarantee that they will have a "License:" line. – Stephen Kitt Feb 21 '16 at 10:19
-1

I only have CentOS systems at hand, you can get to display the package name and license info with the following:

$ rpm -qa --qf "%{name}: %{license}\n"
...
ncurses: MIT
cairo: LGPLv2 or MPLv1.1
dbus-python: MIT
media-player-info: BSD
dbus-x11: GPLv2+ or AFL
NetworkManager: GPLv2+
...

You should be able to do something similar with dpkg-query --license on Ubuntu systems.

Like here, where he uses $ dpkg-query -f='${PackageSpec;-30}\t${Homepage}\n' -W "*" to show only a subset of information per package. Check the dpkg-query options to see if you can get the license form there.

Another interesting post on this, talks exactly about this problematic and that:

At the moment this is poorly supported, though there is an effort under way to provide machine-readable information in the /usr/share/doc/*/copyright files.

  • 2
    There's no such option as dpkg-query --license. Dpkg doesn't keep track of this information. – Gilles 'SO- stop being evil' Feb 18 '16 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.