Disclaimer

This information HAS errors and is made available WITHOUT ANY WARRANTY OF ANY KIND and without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is not permissible to be read by anyone who has ever met a lawyer or attorney. Use is confined to Engineers with more than 370 course hours of engineering.
If you see an error contact:
+1(785) 841 3089
inform@xtronics.com

Cleaning Package Cruft



Cruft was once a problem because it used up valuable disk space - today disk space is about free, yet there are still two good reasons to remove unused bits:
  1. Security - Less tools available - less doors to pick.
  2. Long lists of cruft can confuse debugging efforts.

Find packages that are not fully installed:

$ wajig list |grep -Pv ^ii
There you will see a two letter code

First letter -> desired package state ("selection state"):

Second letter -> current package state:

Third letter -> error state (you normally shouldn't see a third letter, but a space, instead):

So for example:

ii means 'It should be installed and it is installed' whereas
rc means 'It's removed/uninstalled but it's configuration files are still there'

Purge files in config state

(You can replace purge with search to just see them)
$ aptitude purge ~c
# same as aptitude purge ?config-files

Get rid of architecture no longer used

Ferinstance - you once had something that used i386
$ apt-get purge ".*:i386"
$ dpkg --remove-architecture i386

Look for broken packages

$ dpkg --audit

Finding why a package is installed

Some packages get installed due to dependency - they are needed by other packages - others because of recommends and still others due to suggests ( see your apt.conf setting ).

And some Packages are installed because of a tree of depends which makes it hard to figure out where they came from.

Aptitude has a why command - here is an example.

$ aptitude why libxcb-shm0
i   libpoppler46  Recommends poppler-data
i A poppler-data  Suggests   poppler-utils
i A poppler-utils Depends    libcairo2 (>= 1.12.0)
i A libcairo2     Depends    libxcb-shm0 

At the top of the tree - we have libpoppler46 - this package recommended poppler-data  - and via a suggests setting ( see your apt.conf settings to turn this off ) it installed poppler-utils - leading to two more packages installed via dependencies.  At this point it is a good idea to figure out what the top package is for - do you really want it?

$ aptitude show libpoppler46
Returns a line that tells me that

Description: PDF rendering library
Poppler is a PDF rendering library based on Xpdf PDF viewer. 

I remember that I no longer need any pdf rendering so I can remove it from the top.

Find and remove obsolete packages

Obsolete packages are not in any repository on your list anymore - so Lets find them first (you might want to keep them)
$ aptitude show ~o
# which means = aptitude show ?obsolete
Then to delete them:
$ aptitude purge ~o
# which means = aptitude show ?obsolete

Find and remove orphaned packages

Orphaned packages are automatic dependencies whose "dependants" have all been uninstalled.

$ wajig listorphans
$ wajig purgeorphans

Find Autoremove packages

These packages are orphaned packages that were installed by apt to resolve dependencies.
(not sure how to get a list of these first)
$wajig autoremove

Who put that config file in etc?

So if you find /etc/calendar and wonder what it is doing in your headless server.

Base files in stretch

adduser                                                                                                                                                                                                                       
apt                                                                                                                                                                                                                           
apt-listchanges                                                                                                                                                                                                               
apt-utils                                                                                                                                                                                                                     
aptitude                                                                                                                                                                                                                      
aptitude-common                                                                                                                                                                                                               
at                                                                                                                                                                                                                            
base-files                                                                                                                                                                                                                    
base-passwd                                                                                                                                                                                                                   
bash                                                                                                                                                                                                                          
bash-completion                                                                                                                                                                                                               
bc                                                                                                                                                                                                                            
bind9-host                                                                                                                                                                                                                    
bsd-mailx                                                                                                                                                                                                                     
bsdmainutils                                                                                                                                                                                                                  
bsdutils                                                                                                                                                                                                                      
bzip2                                                                                                                                                                                                                         
coreutils                                                                                                                                                                                                                     
cpio                                                                                                                                                                                                                          
cron                                                                                                                                                                                                                          
dash                                                                                                                                                                                                                          
dbus                                                                                                                                                                                                                          
dc                                                                                                                                                                                                                            
debconf                                                                                                                                                                                                                       
debconf-i18n                                                                                                                                                                                                                  
debian-archive-keyring                                                                                                                                                                                                        
debian-faq                                                                                                                                                                                                                    
debianutils                                                                                                                                                                                                                   
diffutils                                                                                                                                                                                                                     
dmidecode                                                                                                                                                                                                                     
dnsutils                                                                                                                                                                                                                      
doc-debian                                                                                                                                                                                                                    
dpkg                                                                                                                                                                                                                          
e2fslibs                                                                                                                                                                                                                      
e2fsprogs                                                                                                                                                                                                                     
exim4                                                                                                                                                                                                                         
exim4-base                                                                                                                                                                                                                    
exim4-config                                                                                                                                                                                                                  
exim4-daemon-light                                                                                                                                                                                                            
file                                                                                                                                                                                                                          
findutils                                                                                                                                                                                                                     
ftp                                                                                                                                                                                                                           
gcc-4.8-base                                                                                                                                                                                                                  
gcc-4.9-base                                                                                                                                                                                                                  
gcc-6-base                                                                                                                                                                                                                    
gettext-base                                                                                                                                                                                                                  
gnupg                                                                                                                                                                                                                         
gpgv                                                                                                                                                                                                                          
grep                                                                                                                                                                                                                          
groff-base                                                                                                                                                                                                                    
gzip                                                                                                                                                                                                                          
hdparm                                                                                                                                                                                                                        
host                                                                                                                                                                                                                          
hostname                                                                                                                                                                                                                      
ifupdown                                                                                                                                                                                                                      
info                                                                                                                                                                                                                          
init                                                                                                                                                                                                                          
init-system-helpers                                                                                                                                                                                                           
initscripts                                                                                                                                                                                                                   
install-info                                                                                                                                                                                                                  
iproute2                                                                                                                                                                                                                      
iptables                                                                                                                                                                                                                      
iputils-ping                                                                                                                                                                                                                  
isc-dhcp-client                                                                                                                                                                                                               
isc-dhcp-common                                                                                                                                                                                                               
kmod                                                                                                                                                                                                                          
krb5-locales                                                                                                                                                                                                                  
less                                                                                                                                                                                                                          
libacl1                                                                                                                                                                                                                                                                                                                                                                                                                                       
locales                                                                                                                                                                                                                       
login                                                                                                                                                                                                                         
logrotate                                                                                                                                                                                                                     
lsb-base                                                                                                                                                                                                                      
lsof                                                                                                                                                                                                                          
m4                                                                                                                                                                                                                            
man-db                                                                                                                                                                                                                        
manpages                                                                                                                                                                                                                      
mawk                                                                                                                                                                                                                          
mime-support                                                                                                                                                                                                                  
mlocate                                                                                                                                                                                                                       
mount                                                                                                                                                                                                                         
multiarch-support                                                                                                                                                                                                             
mutt                                                                                                                                                                                                                          
nano                                                                                                                                                                                                                          
ncurses-base                                                                                                                                                                                                                  
ncurses-bin                                                                                                                                                                                                                   
ncurses-term                                                                                                                                                                                                                  
net-tools                                                                                                                                                                                                                     
netbase                                                                                                                                                                                                                       
netcat-traditional                                                                                                                                                                                                            
nfacct                                                                                                                                                                                                                        
nfs-common                                                                                                                                                                                                                    
openssh-client                                                                                                                                                                                                                
passwd                                                                                                                                                                                                                        
patch                                                                                                                                                                                                                         
pciutils                                                                                                                                                                                                                      
perl                                                                                                                                                                                                                          
perl-base                                                                                                                                                                                                                     
perl-modules                                                                                                                                                                                                                  
perl-modules-5.24                                                                                                                                                                                                             
procmail                                                                                                                                                                                                                      
procps                                                                                                                                                                                                                        
python                                                                                                                                                                                                                        
python-apt                                                                                                                                                                                                                    
python-minimal                                                                                                                                                                                                                
python-reportbug                                                                                                                                                                                                              
python-support                                                                                                                                                                                                                
python2.7                                                                                                                                                                                                                     
python3-reportbug                                                                                                                                                                                                             
readline-common                                                                                                                                                                                                               
reportbug                                                                                                                                                                                                                     
rpcbind                                                                                                                                                                                                                       
rsyslog                                                                                                                                                                                                                       
sed                                                                                                                                                                                                                           
sensible-utils                                                                                                                                                                                                                
startpar                                                                                                                                                                                                                      
systemd                                                                                                                                                                                                                       
systemd-sysv                                                                                                                                                                                                                  
sysv-rc                                                                                                                                                                                                                       
sysvinit-utils                                                                                                                                                                                                                
tar                                                                                                                                                                                                                           
tasksel                                                                                                                                                                                                                       
tasksel-data                                                                                                                                                                                                                  
telnet                                                                                                                                                                                                                        
texinfo                                                                                                                                                                                                                       
time                                                                                                                                                                                                                          
traceroute                                                                                                                                                                                                                    
tzdata                                                                                                                                                                                                                        
ucf                                                                                                                                                                                                                           
udev                                                                                                                                                                                                                          
util-linux                                                                                                                                                                                                                    
vim-common                                                                                                                                                                                                                    
vim-tiny                                                                                                                                                                                                                      
w3m                                                                                                                                                                                                                           
wamerican                                                                                                                                                                                                                     
wget                                                                                                                                                                                                                          
whiptail                                                                                                                                                                                                                      
whois                                                                                                                                                                                                                         
xz-utils                                                                                                                                                                                                                      
zlib1g 

Top Page wiki Index