I want to write a script that outputs the license for every software package installed on my system.

Using dpkg --get-selections I am able to get list of everything installed. However, I don't see a way to get the license information for each package. For example, I can use aptitude show to get the properties of each package, but that does not include the license:

$ aptitude show apache2
Package: apache2
State: installed
Automatically installed: no
Version: 2.2.14-5ubuntu8.6
Priority: optional
Section: httpd
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 36.9k
Depends: apache2-mpm-worker (= 2.2.14-5ubuntu8.6) | apache2-mpm-prefork (= 2.2.14-5ubuntu8.6) | apache2-mpm-event (= 2.2.14-5ubuntu8.6) | apache2-mpm-itk (= 2.2.14-5ubuntu8.6),
         apache2.2-common (= 2.2.14-5ubuntu8.6)
Provided by: apache2-mpm-event, apache2-mpm-itk, apache2-mpm-prefork, apache2-mpm-worker
Description: Apache HTTP Server metapackage
 The Apache Software Foundation's goal is to build a secure, efficient and extensible HTTP server as standards-compliant open source software. The result has long been the
 number one web server on the Internet. 

 It features support for HTTPS, virtual hosting, CGI, SSI, IPv6, easy scripting and database integration, request/response filtering, many flexible authentication schemes, and
Homepage: http://httpd.apache.org/

Is there a third-party repository that correlates the license to each package?

It sounds painful to download every source package and inspect it for licensing information, but maybe that's the best way.


Here's what I ended up doing. (results in ~/licenses.txt with all the licenses that exist in /usr/share/doc)

$ packages=`dpkg --get-selections | awk '{ print $1 }'`
$ for package in $packages; do echo "$package: "; cat /usr/share/doc/$package/copyright; echo ""; echo ""; done > ~/licenses.txt
| improve this answer | |
  • 4
    This is very roundabount. Simply grep '^' /usr/share/doc/*/copyright will get you much the same information, or tail -n 10000 /usr/share/doc/*/copyright if you don't want the file name prefix on every line. – tripleee Jan 28 '16 at 4:07

In 2012, Debian released the document Machine-readable debian/copyright which will make licenses readable in the future. Currently, not all packages use this format. The command

grep -h '^License:' /usr/share/doc/*/copyright | sort -i | uniq -ic | sort -n

still returns a lot of garbage. For a better output you probably need a tool which parses each file depending on the Format: field value.

A completely different way is the file structure in /usr/share/common-licenses/ (thx to https://stackoverflow.com/questions/1884753/license-info-of-a-deb-package#1884785). It lists the main licenses used in debian-based distributions (and contains their license texts). This list is provided by the package base-files and is not linked to the list of installed packages, but it's probably enough information for the average boss/customer.

ls /usr/share/common-licenses/
Apache-2.0  BSD   GFDL-1.2  GPL    GPL-2  LGPL    LGPL-2.1
Artistic    GFDL  GFDL-1.3  GPL-1  GPL-3  LGPL-2  LGPL-3

Update I just published a simple command-line solution which extracts the license information from the copyright files with a lot of heuristics. https://github.com/daald/dpkg-licenses. Feel free to try it. Any suggestions are welcome.

| improve this answer | |

I just stumble on dpkg-licenses (https://github.com/daald/dpkg-licenses).

Just clone the repo

git clone https://github.com/daald/dpkg-licenses.git


./dpkg-licenses > licenses.txt

And you have the best of today softwares installed, versions and licenses tabular list you can dream of...

| improve this answer | |
  • @Daniel Alder already referred to the same link in another answer askubuntu.com/a/620069/24203 and he seems to be the author of the tool :) – IsaacS Jun 22 '18 at 4:17

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.