Ubuntu – How to find out the license for each of the installed applications/packages

licensesUbuntu

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

Best Answer

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.

Related Question