a command to list all packagas installed on the system and their installed files, how?

I am using Ubuntu 14.04 LTS, Trusty. I want to execute a command to list all the installed packages of the system and for each packages name , it should list all the files that package has installed on the system. how I can do that?


You can run the following command to print this information in the terminal:

for i in $(echo $(apt list 2>&1| grep installed | sed 's|/.*$||g')); do echo $i; dpkg -L $i | grep -P '^.'$i'|$'; done | tee APTINSTALLED | grep -P '^[a-z0-9].*$|$'

The command also creates a file with this information named APTINSTALLED.

Alternatively, if you would like to list all of the files of an installed package, you can run the command dpkg -L followed by the package name.

For example, to list all the files installed with the package gnome-terminal, run the following command:

dpkg -L gnome-terminal

If you just want to list all installed packages, you can run the following command:

apt list 2>&1| grep installed | sed 's|/|  |g;s|\[.*$||g' | GREP_COLOR='0;32' grep --color=auto -P '^.*  '

If you only want to list the installed packages without the extra information, you can run this instead:

apt list 2>&1| grep installed | sed 's|/.*$||g'

If you would like to list the installed package names in a linear form instead of a column, you can run the following command:

echo $(apt list 2>&1| grep installed | sed 's|/.*$||g')

Finally, if you would like to list all installed packages and a brief description of each package, run the following command:

dpkg -l | grep --color=always ii

The last command will highlight "ii" in red which is printed directly before each package name to make it easier to distinguish between the package names and the descriptions.

Or, you could just run the following command instead:

dpkg -l

Additionally as suggested by @steeldriver in a comment, you can use the -f flag with the dpkg-query command to print the name. Here's an example:

dpkg-query -W -f='${Package}\n' | while read -r p; do echo "$p" & dpkg-query -L "$p"; done

and here it is with the package name highlighted in green:

dpkg-query -W -f='${Package}\n' | while read -r p; do echo "$p" & dpkg-query -L "$p"; done | GREP_COLOR='0;32' grep -P --color=auto '^[a-z0-9].*$|$'

and here it is in the form of a script that will create a new directory ~/packagefiles. Executing this script will create a text file for each package installed in the new directory. Each text file contains the list of files for each package. This will also print in the terminal as normal, each package name highlighted in green:

#!/bin/bash
mkdir -p /home/$USER/packagefiles 2>&1
dpkg-query -W -f='${Package}\n' | while read -r p; do echo "
$p" & dpkg-query -L "$p" | tee /home/$USER/packagefiles/"$p"; done | GREP_COLOR='0;32' grep -P --color=auto '^[a-z0-9].*$|$'

This is convenient because each package is listed in the directory and so ls ~/packagefiles will list all packages in nice columns.

Don't forget to make the script executable.


If we're dealing with apps that were installed via apt, that's pretty simple if you know that each package has /var/lib/dpkg/info/*.list file. We can print file name as package name, and contents of those files contain all the files that came with package during installation. In other words, this:

for file in /var/lib/dpkg/info/*.list ; do echo ">>> $(basename ${file%%.*})" ; cat "$file" ; done

If the software came with git or other means ( not dpkg or apt ) then there's not really a way to tell which files may have been added to your system.