Skip to content

Clear dpkg status file

Published on: October 29, 2006 | Last modified on: January 17, 2009

I noticed that after a few months of use, my /var/lib/dpkg/status file contained a lot of useless information about the packages I had installed and then purged – those packages have a status called “purge ok not-installed” (this is typically the case for kernel images built with make-kpkg and installed with dpkg -i). The grep-dctrl package is able to count/show these packages:

# Shows the packages with "purge ok not-installed" status
/usr/bin/grep-status "purge ok not-installed" /var/lib/dpkg/status

or

# Just counts these packages
/usr/bin/grep-status "purge ok not-installed" -c /var/lib/dpkg/status

However, I was unable to find something to purge the status file (equivalent to dpkg --forget-old-unavail). I have thus written this small script together with people from the debian-user-french mailing-list. It makes backups of your current status file, and keeps compressed backups from the last 7 times the script is launched – this should not prevent you from keeping your own backup of this precious file!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /bin/bash
#
# clear-dpkg-status - (c) 2005-2007 Julien Valroff
#
# Clears dpkg status file marked as "purge ok not-installed"
#
 
if [ $UID != 0 ]; then
    echo "This script requires to be root"
    exit 1;
fi
 
rep=/var/lib/dpkg
 
cp $rep/status $rep/status.backup
savelog -p -q -c 7 $rep/status.backup && rm -f $rep/status.backup > /dev/null 2>&1
 
sed -i -e '/./,$!d' -e ':a;N;/\n$/!{$!b a};/\nStatus: purge ok not-installed\n/d' $rep/status
 
if [ $? = 0 ]
then
  echo "Done."
else
  echo "Script exited with code $?."
fi

Use at your own risk!