How to recover deleted "dpkg" directory?

Using root and recursive rm (rm -r) is a recipe for disasters, don't do it. The files and directories that were deleted are as follows:

ls -l /var/lib/dpkg/
total 9964
drwxr-xr-x 2 root root    4096 nov 28 11:18 alternatives
-rw-r--r-- 1 root root      11 sep 18 14:08 arch
-rw-r--r-- 1 root root 2573807 nov 28 11:18 available
-rw-r--r-- 1 root root 2561322 nov 28 10:25 available-old
-rw-r--r-- 1 root root       8 abr 24  2013 cmethopt
-rw-r--r-- 1 root root     538 sep 25 17:24 diversions
-rw-r--r-- 1 root root     457 sep 25 17:24 diversions-old
drwxr-xr-x 2 root root  483328 nov 28 11:17 info
-rw-r----- 1 root root       0 nov 28 11:18 lock
drwxr-xr-x 2 root root    4096 mar 22  2013 parts
-rw-r--r-- 1 root root     135 abr 24  2013 statoverride
-rw-r--r-- 1 root root 2269113 nov 28 11:18 status
-rw-r--r-- 1 root root 2268870 nov 28 11:18 status-old
drwxr-xr-x 2 root root    4096 nov 28 11:18 triggers
drwxr-xr-x 2 root root    4096 nov 28 11:18 updates

You removed 5 directories, the status file, etc. So, lets try to fix the stuff. First, create the directory:

sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates}

Recover some backups:

sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status

Check if dpkg is working:

apt-get download dpkg
sudo dpkg -i dpkg*.deb

If everything is "ok" then repair your base files too:

apt-get download base-files
sudo dpkg -i base-files*.deb

Now try to update your package list, etc.:

dpkg --audit
sudo apt-get update
sudo apt-get check

Compare ls -l /var/lib/dpkg with the above list. If some -old file is not present don't worry it as it would be created with the normal usage of the system.


Well dpkg (Debian package management system ) package provides the low-level infrastructure for handling the installation and removal of Debian software packages.So removing it was not a good idea, and you can can it back by-

Downloading the file by using wget :

wget https://launchpad.net/ubuntu/+archive/primary/+files/dpkg_1.16.1.2ubuntu7.2.tar.bz2

Extract it in xxx folder.

tar -xvf dpkg_1.16*
cd dpkg-1.16*
./configure
make
sudo make install

hope it will work.