Skip to content

Instantly share code, notes, and snippets.

@jameshfisher
Created April 12, 2014 17:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jameshfisher/10547691 to your computer and use it in GitHub Desktop.
Save jameshfisher/10547691 to your computer and use it in GitHub Desktop.
Restore a file from the package that provides it.
#!/bin/bash
# Usage:
#
# sudo ./restore-file-from-package.sh <filepath>
#
# Restore a file from the package that provides it.
#
# Source: http://askubuntu.com/a/67028/30482
set -x
set -e
FILE_TO_RESTORE=$(readlink -e $1)
mv -n ${FILE_TO_RESTORE} ${FILE_TO_RESTORE}.bak
apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall $(dpkg -S ${FILE_TO_RESTORE} | head -1 | cut -d ':' -f1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment