Which package owns this file?

Filepkg.sh is another one of those scripts borne of a personal itch. I’m spending a fair amount of time cleaning up both Redhat and Debian boxes which have custom software installed, some of it by hand and some via the package management system (we build the packages ourselves).

One of the annoyances I’ve come across while determining which files are managed and which were left by us is that while both dpkg and rpm will tell you the package that owns a file, you need to provide the full path of the file you’re asking about to get the information out. Well no more!

filepkg.sh takes a file name as an argument and tries to do a ‘which’ command on it. If this works then the full path is passed to the native package manager (filepkg.sh currently supports Redhat and Debian) and the owning package, if there is one, is returned. If filepkg.sh is called with a ‘-l’ as the first argument or ‘which’ doesn’t find a file with that name (‘which’ doesn’t deal with config files for example) then the file is passed to ‘locate’; it then looks up the file and passes it to the package manager to get a package name back.

The idea is simple, the code’s easy to read and it works how I want it so feel free to do what you want with this little chunk of GPL’d code.