How do I get a list of files that were or will-be installed when I apt-get a package? Conversely, can I find what package(s) caused a particular file to be installed?
-
Similar on SU http://superuser.com/questions/82923/how-to-list-files-of-a-debian-package-without-install on Ubuntu: http://askubuntu.com/questions/32507/how-do-i-get-a-list-of-installed-files-from-a-package – Ciro Santilli OurBigBook.com May 12 '15 at 10:56
-
Both ubuntu and debian have web for this, for example https://packages.ubuntu.com/focal/amd64/tldr/filelist – Rick Jun 21 '22 at 08:29
6 Answers
Note: in the following commands, a command beginning with 'root#' means it needs to be run as root.
To find which files were installed by a package, use dpkg -L:
$ dpkg -L $package
apt-file can tell you which files will be installed by a package before installing it:
root# apt-get install apt-file
root# apt-file update
$ apt-file list $package
Or if you have the package as a .deb file locally already, you can run dpkg on it:
$ dpkg --contents $package.deb
To find which package provides a file that is already on your system, use:
$ dpkg -S /path/to/file
To find which package provides a file that is not currently on your system, use apt-file again:
$ apt-file search /path/to/file
-
13Keep in mind that while this will get you most of what you need it will not give you everything. Several packages create configuration files as part of their setup scripts. These files will not be reported by dpkg. – Zoredache Dec 23 '09 at 17:33
-
$ dpkg -L packagenot$ dpkg -L $packageputting the $ in front of the package names returns an error – Alecz Jan 14 '17 at 21:50 -
2The dollar is meant to be understood as a variable, meaning you need to replace
$packagewith the actual name of the package. – raphink Jan 15 '17 at 23:37 -
2conffiles of a package (if any) are listed by command
dpkg --status $package. For the reverse operation usegrep $filename /var/lib/dpkg/info/*.conffiles. – Uwe Geuder Mar 08 '18 at 17:38 -
1
-
1@samshers,
apt-file updatecommand populates the db whichapt-fileuses for searches. – Victor Yarema Oct 28 '20 at 19:49 -
1
-
2@confiq if you don't have apt-file, run
sudo apt-get -y install apt-filethen runsudo apt-file update. After that you can use the tool as described above. – Speeddymon Jan 10 '22 at 18:24 -
I find
apt-file list $packagethe most useful.dpkg -L $packagelists directories. Thanks! – Rick Jun 21 '22 at 08:28 -
I still think my answer is the best because it never has to download anything to disk, but that is just me being biased :p – linuxgeek Nov 22 '22 at 19:27
Here is a function that should do it for you without the need to downloading the package to disk. This solution also doesn't require any third party programs (like apt-file) or anything outside of a minimum debian/ubuntu install.
# Function that gets the package layout of a remote package from
# apt/apt-get/aptitude/synaptic/etc...
apt_list ()
{
# Build array of packages
local packages=("$@");
# Iterate package indexes up to the length of the array minus 1
for pkg in $(seq 0 1 $((${#packages[@]}-1)));
do
# Pretty little separator in case you are examining the
# contents of multiple packages.
echo -e "\n#### ${packages[$pkg]} ####\n";
# Pipe steps (in order)
# Print the url to the .deb package remote location from sources.list
# delimit by single quotes and select only the url
# pipe the url to xargs after a curl silent follow redirects
# insecure (no cert checking some may wish to take the -k off
# the curl command.
# use dpkg -c to check the contents of the downloaded package in stdin
# Use perl to remove dots after modification timestamp on sysroot
apt-get download -o Dir::Cache::archives="./" --print-uris ${packages[$pkg]}\
| awk -F\' '{print $2}' | xargs -I '{}' curl -skL '{}' |\
dpkg-deb -c /dev/stdin | perl -ne 's,(:\d\d )[.]/,$1/,g;print';
# Line break so the last package name doesn't wind up on same line as PS1
echo;
# end loop
done
}
Then use apt_list <package name1> [package name 2]
e.g.
apt_list curl wget
In regard to your second question you can use dpkg -S /path/to/isntalled/file or if you are trying to view the contents of an already downloaded/local .deb file with dpkg --contents </path/to/deb/file>. As for reverse checking files from packages where you don't know the name of the package that owns said file, a third party solution apt-file (a software package that indexes the contents of packages in your available repositories and allows you to search for a particular file among all available packages), is available. This is like yum provides on rhel based systems like CentOS) would be the best bet.
- 110
dpkg -S /path/to/file/in/question
As far as I'm concerned, dpkg is the low-level tool that apt-get depends on.
- 918
- 5
- 7
-
Yes, dpkg is the command that adds and removes software and files from you mcomputer. apt (incl. Apt-get, aptitude, synaptic, etc.) is the programme that calls dpkg – Amandasaurus May 09 '10 at 12:06
Another option for those of you who using Linux Mint:
apt content <packageName>
- 21
-
-
hm, it works on my system. what apt version do you use? you can check apt version with 'apt show apt' command. mine is 2.4.10 – folivore Nov 12 '23 at 22:02
-
apt --versiongivesapt 2.4.10 (amd64). I don't seecontentdocumented anywhere. Do you haveaptaliased to anything? (type -a apt) – SpinUp __ A Davis Nov 13 '23 at 04:58 -
22:14:~$ type -a apt apt is /usr/local/bin/apt apt is /usr/bin/apt apt is /bin/apt– folivore Nov 25 '23 at 20:22 -
hm...
22:23:~$ which apt /usr/local/bin/apt 22:23:~$ file /usr/local/bin/apt /usr/local/bin/apt: Python script, ASCII text executable
– folivore Nov 25 '23 at 20:24 -
22:24:~$ apt show apt Package: apt Version: 2.4.11 Priority: important Build-Essential: yes Section: admin Origin: Ubuntu Maintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com Original-Maintainer: APT Development Team deity@lists.debian.org Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 4 240 kB – folivore Nov 25 '23 at 20:25
-
Example of apt content output:
– folivore Nov 25 '23 at 20:2622:25:~$ apt content apt /. /etc /etc/apt /etc/apt/apt.conf.d /etc/apt/apt.conf.d/01autoremove /etc/apt/apt.conf.d/01-vendor-ubuntu /etc/apt/auth.conf.d /etc/apt/keyrings /etc/apt/preferences.d -
I'm using Linux Mint btw:
– folivore Nov 25 '23 at 20:2922:28:~$ cat /etc/issue Linux Mint 21.2 Victoria -
contentmust be a feature of that python script you have in/usr/local/bin, I guess – SpinUp __ A Davis Nov 26 '23 at 18:08 -
Looks like it is. I just found this: https://salsa.debian.org/apt-team/apt/-/blob/main/cmdline/apt.cc
APT is an util written in C++. I kind of pissed by how deeply Python is integrated in Ubuntu and its derivatives. You can't use any of those distributives without installing Python. Is Debian also tied that much with Python or any other JIT or scripting language except Bash and C++?
– folivore Nov 26 '23 at 21:22 -
-
23:39:/usr/local/bin$ apt contains /usr/local/bin/apt mintsystem: /usr/local/bin/apt
yep, Q.E.D.
btw, 'contains' is another example of a Mint addition to the apt tool.
– folivore Nov 26 '23 at 21:43 -
Interesting -- good to know about these minty additions to apt. – SpinUp __ A Davis Nov 27 '23 at 14:21
If you have installed dlocate, you can use dlocate -L the same way as dpkg -L. It works exactly the same in this case, but has a number of other options.
- 343
The apt-file command needs to download a database that can be 100's of MB and take several minutes. If you're only interested in one or two packages, it's quicker to download the deb file(s) and view the contents using standard tools.
# change to a directory where you have write permission
cd /tmp
download the package's .deb file, e.g. for dbab
apt download dbab
print the files that will be installed by the package
dpkg -c dbab_1.5.8-1_all.deb
Furthermore, you can extract the control files from the package, and see what the scripts will do on installation or removal. Particularly, the post-install script may be of interest.
# this will extract the control files to a new dir, ctrl-files
dpkg -e dbab_1.5.8-1_all.deb ctrl-files
then they can be viewed, e.g.
more ctrl-files/postinst