2

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?

  • 3
    Possible duplicate of How to list all installed packages – Bruni Nov 7 '16 at 13:59
  • why do you need this? – Anwar Nov 8 '16 at 6:23
  • no, it is not a duplicate question. I not only want to list the installed packages but also the files for them. The question has been answered very well – ali Nov 8 '16 at 8:45
4

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.

  • Nice! +1 for the putting the package name above its contents. I was wondering how to do that. Got the rest with dpkg-query -L $(dpkg-query -l "*" | grep "^ii" | cut -d " " -f3) – Ron Nov 7 '16 at 13:55
  • 1
    @Ron or use the -f option of dpkg-query to output just the package names e.g. dpkg-query -W -f='${Package}\n' | while read -r p; do dpkg-query -L "$p"; done – steeldriver Nov 7 '16 at 17:31
  • @steeldriver To print the name along with the listed files, I had to throw an echo "$p" in there but I must admit that echo behaves much more nicely with dpkg-query than it does with apt-list – mchid Nov 7 '16 at 18:39
  • @ali I have added some stuff to the answer. – mchid Nov 7 '16 at 19:12
  • @mchid, wonderful, the commands are complicated (showing your expertise) but the result is outstanding. Thank you for the beautiful solutions – ali Nov 8 '16 at 8:36
1

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.

  • 1
    Thank you for your information, your command perfectly works fine – ali Nov 8 '16 at 8:37
0

cat /var/lib/dpkg/available | grep Package

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.