Flash Notes

Commands - Package finding


• How to find the name of the package containing a given command ?

Solution

Use rpm -qf on RedHat or dpkg -S on Debian

Program

#!/bin/bash

if [ "$1" = "" -o "$2" != "" ]; then
echo "Display the name of the package containing the specified command name."
echo "Usage: `basename $0` command_name"
exit 1
fi

if [ -f "/etc/redhat-release" ]; then
rpm -qf `type -p $1`
elif [ -f "/etc/debian_version" ]; then
dpkg -S `type -p $1`
else
echo "Unknown operating system !" >&2
exit 1
fi

Example 1

$ srcpkg bvi
bvi: /usr/bin/bvi

Example 2

$ srcpkg ls
coreutils: /bin/ls

Example 3

$ srcpkg find
findutils: /usr/bin/find