Ubuntu: Determining the package origin of a file

ubuntuIf you are on an Ubuntu host and need to determine from which package a file originated, the ‘dpkg’ utility has this ability.

For example, if you need to know which package the ‘mkpasswd’ binary came from:

$ which mkpasswd
/usr/bin/mkpasswd

$ dpkg -S /usr/bin/mkpasswd
whois: /usr/bin/mkpasswd

Which tell us it came from the ‘whois’ package.

And if you then wanted to see all the files that were created by the ‘whois’ package:

$ dpkg -L whois

/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/whois
/usr/share/doc/whois/README
/usr/share/doc/whois/changelog.gz
/usr/share/doc/whois/copyright
/usr/share/man
/usr/share/man/man5
/usr/share/man/man5/whois.conf.5.gz
/usr/share/man/man1
/usr/share/man/man1/whois.1.gz
/usr/share/man/man1/mkpasswd.1.gz
/usr/bin
/usr/bin/whois
/usr/bin/mkpasswd

 

REFERENCES

https://linux.die.net/man/1/dpkg (man page)

https://askubuntu.com/questions/481/how-do-i-find-the-package-that-provides-a-file

https://unix.stackexchange.com/questions/306872/how-can-i-list-all-files-which-have-been-installed-by-an-apt-package

NOTES

upgrading a single package using apt

apt install --only-upgrade <pkgname>