#!/bin/bash
# Subject: Find the package that installed a command
# 
# <http://www.commandlinefu.com/commands/view/18250/find-the-package-that-installed-a-command>
# 
# $ whatinstalled () { local cmdpath=$(realpath -eP $(which -a $1 | grep 
# -E "^/" | tail -n 1) 2>/dev/null) && [ -x "$cmdpath" ] && dpkg -S 
# $cmdpath 2>/dev/null | grep -E ": $cmdpath\$" | cut -d ":" -f 1; }
# 
# Put this one-line function somewhere in your shell init, re-login and 
# try whatinstalled <command>
# 
# This is an elaborate wrapper around "dpkg -S", with numerous safeguards. 
# Symlinks and command aliases are resolved. If the searched command is 
# not an existing executable file or was installed by some other means 
# than dpkg/apt, nothing is printed to stdout, otherwise the package name.

cmdpath=$(realpath -eP $(which -a $1 | grep -E "^/" | tail -n 1) 2>/dev/null) && [ -x "$cmdpath" ] && dpkg -S $cmdpath 2>/dev/null | grep -E ": $cmdpath\$" | cut -d ":" -f 1


syntax highlighted by Code2HTML, v. 0.9.1