In Ubuntu machine sometime we need to list all files which are present in any Ubuntu packages.This is really important to know when we need to know all files which comes to get through any installed or uninstalled packages.

To get this list we can use two Ubuntu commands apt-file and dpkg

To get file list of uninstalled package.


If we need to know list of files of any uninstalled packages. we can use apt-file commandused to get various details of all packages in apt-file which we should update time to time.

root@srv2:~# apt-file list targetcli-fb
targetcli-fb: /usr/bin/targetcli
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/__init__.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/ui_backstore.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/ui_node.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/ui_root.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/ui_target.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli/version.py
targetcli-fb: /usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/PKG-INFO
targetcli-fb: /usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/dependency_links.txt
targetcli-fb: /usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/top_level.txt
targetcli-fb: /usr/share/doc/targetcli-fb/changelog.Debian.gz
targetcli-fb: /usr/share/doc/targetcli-fb/copyright
targetcli-fb: /usr/share/man/man8/targetcli.8.gz

We should update apt-file database like below commands.

root@srv2:~# apt-file update
Hit:1 http://ppa.launchpad.net/gns3/ppa/ubuntu bionic InRelease
Hit:2 http://gb.archive.ubuntu.com/ubuntu bionic InRelease                                          
Get:3 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]                        
Hit:4 http://archive.canonical.com/ubuntu bionic InRelease                                          
Ign:5 http://dell.archive.canonical.com/updates bionic-dell-beaver-turtlebay InRelease              
Ign:6 http://dell.archive.canonical.com/updates bionic-dell-service InRelease                       
Hit:7 http://dell.archive.canonical.com/updates bionic-dell InRelease                               
Ign:8 http://oem.archive.canonical.com/updates bionic-oem InRelease                                 
Hit:9 http://ppa.launchpad.net/team-xbmc/ppa/ubuntu bionic InRelease                                
Hit:10 http://dl.google.com/linux/chrome/deb stable InRelease                                       
Hit:11 http://dell.archive.canonical.com/updates bionic-dell-beaver-turtlebay Release               
Hit:12 http://oem.archive.canonical.com/updates bionic-oem Release                                  
Get:13 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]                     
Hit:14 http://dell.archive.canonical.com/updates bionic-dell-service Release                        
Get:15 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                        
Hit:16 http://ppa.launchpad.net/x2go/stable/ubuntu bionic InRelease                                 
Get:17 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main i386 Packages [714 kB]
Get:19 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1,010 kB]
Get:22 http://gb.archive.ubuntu.com/ubuntu bionic-updates/main amd64 DEP-11 Metadata [295 kB]
Get:23 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1,092 kB]  
Get:24 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [46.1 kB]
Get:25 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe i386 Packages [1,025 kB]         
Get:26 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 DEP-11 Metadata [49.2 kB]
Get:27 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 DEP-11 Metadata [2,464 B] 
Get:28 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 DEP-11 Metadata [279 kB]
Get:29 http://gb.archive.ubuntu.com/ubuntu bionic-updates/universe DEP-11 64x64 Icons [458 kB]
Get:30 http://gb.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 DEP-11 Metadata [2,468 B]
Get:31 http://gb.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 DEP-11 Metadata [9,288 B]
Fetched 5,235 kB in 2s (2,762 kB/s)                                
Reading package lists... Done
Building dependency tree       
Reading state information... Done
2 packages can be upgraded. Run 'apt list --upgradable' to see them.

How to get file list of Installed packages


We can also get file details of packages that were install on Ubuntu machines in case we don’t have apt-file installed on machine.
For this we can list file through dpkg command which usually use to get list of packages used on Ubuntu machine. But we can also use it to file list of packages.

root@srv2:~# dpkg -L targetcli-fb
/.
/usr
/usr/bin
/usr/bin/targetcli
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/targetcli
/usr/lib/python3/dist-packages/targetcli/__init__.py
/usr/lib/python3/dist-packages/targetcli/ui_backstore.py
/usr/lib/python3/dist-packages/targetcli/ui_node.py
/usr/lib/python3/dist-packages/targetcli/ui_root.py
/usr/lib/python3/dist-packages/targetcli/ui_target.py
/usr/lib/python3/dist-packages/targetcli/version.py
/usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info
/usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/PKG-INFO
/usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/targetcli_fb-2.1.fb43.egg-info/top_level.txt
/usr/share
/usr/share/doc
/usr/share/doc/targetcli-fb
/usr/share/doc/targetcli-fb/changelog.Debian.gz
/usr/share/doc/targetcli-fb/copyright
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/targetcli.8.gz

or 

dpkg --listfiles targetcli-fb

So now we know we can get all file list of install and uninstall packages.