Gentoo Wiki


This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other


What is Cruft?

   "Over time, any system builds up cruft."
         Redmond concerned anonymous

Files and directories that don't belong to any package.

"This script tries to list all the cruft on a system with as few as possible false positives to help you keep your system in good working order. Note that plenty of packages drop extra files all over the place; any extra help is appreciated."

The term "cruft" imbues worth (or lack of worth) to files that may well be important.

Install findcruft

Warning: Always verify the origin of programs, especially if you are to run the program as root! If you cannot verify that the origin is trustable (anyone can change the below adress) then you must verify that the program doesn't do anything nasty! Don't say I didn't warn you! Portage guys, can't we get this in the main tree instead?

First you should add /usr/local/portage in your PORTDIR_OVERLAY variable in /etc/make.conf

Then download the ebuild in your overlay and emerge it:

mkdir -p /usr/local/portage
cd /usr/local/portage
tar xjf findcruft-ebuild.tar.bz2
rm -f findcruft-ebuild.tar.bz2
ebuild /usr/local/portage/app-portage/findcruft/findcruft-1.0.4-r1.ebuild digest
ACCEPT_KEYWORDS="~x86" emerge findcruft

Run the Script

root# findcruft | tee cruft.out

This will output all the files and dirs that are considered cruft to your shell and a file called cruft.out. Each file is on a new line. This will enable you to use the cat command along with rm to delete all of the cruft. Before you do this, though, you must look through the cruft.out and make sure there are no files you want to keep.

Cleaning up Cruft.out

root# nano -w cruft.out

Remove each file's line of the files you wish to keep. All lines in this file will remove the corresponding file.

Warning: Always review what files are considered cruft. If you remove all files listed in cruft.out without looking through them and taking out the ones you are not absolutely sure are cruft, you are very likely to break your system. To reduce the risk, you can move the cruft instead.

Move the cruft

If you are not sure if you can delete the cruft you can move it in another directory to restore it easily later. You can use this script:

File: mvcruft
scalar(@ARGV) == 2 or die "Usage: mvcruft cruftfile backupdir\n";
open FILELIST, "$ARGV[0]" or die "Cannot open cruft file: $ARGV[0]\n";

        system("mkdir -p -- \"$CRUFTDIR$1\" && `[ -e \"$1$2\" ] || [ -h \"$1$2\" ]`  && mv -- \"$1$2\" \"$CRUFTDIR$1$2\"");

root# chmod 755 mvcruft
root# mvcruft /path/to/cruft.out /home/backup_dir

Deleting the Cruft

root# xargs rm -rf < cruft.out

xargs executes the following command, taking the output from stdin as arguments

rm -rf recursively deletes folders and files.

Re-run the Script

root# rm cruft.out

Re-run the script to make sure everything was removed that you want to be.

False Positives

if you think they are false positives and know to which package they belong you can create/edit a rule file in /usr/lib/findcruft/<category>/<package>.
Then, we can exchange these rule files and build new rule archives from time to time.
If it is a false positive due to a personal/local setting on your machine, you can add it into /usr/lib/findcruft/ignore; there it won't interfere with the exchanged rules.

False Positives rules needed

You can here add your false positives:

echo /var/log
echo /var/lock
echo /var/run
echo /var/lib/init.d
echo /etc/udev/rules.d/10-local.rules
echo /etc/udev/scripts
echo /lib/udev/devices
echo /var/www
echo /usr/src
echo /etc/profile.csh
echo /etc/eselect/ld-mtimedb 
cruftdir /var/lib/wxwidgets
echo /var/run/
echo /usr/bin/vmware
cruftdir /var/lib/cache/beagle/indexes
cruftdir /var/lib/cache/beagle
echo /var/spool/uptimed/bootid
echo /var/spool/uptimed/records
echo /usr/bin/abiword
echo /var/cache/eix
cruftdir /var/cache/kuroo
echo /usr/bin/bash
cruftdir /etc/sgml
cruftdir /var/lib/texmf
echo /var/run/svc-started-mysqld
echo /var/db/webapps/phpmyadmin
cruftdir /etc/ssl/certs
echo /usr/lib/
echo /usr/lib/xorg/modules/extensions/
echo /etc/samba/smb.conf
cruftdir /var/lib/dhcp
echo /etc/ntp.conf
echo /var/run/
echo /var/run/ 
echo /etc/tor/torrcecho 
cruftdir /var/cache/squid
cruftdir /var/lib/boinc
echo /var/lib/dbus/machine-id
echo /var/run/dbus/system_bus_socket
echo /var/run/
echo /var/lib/cache/hald/fdi-cache
echo /usr/bin/sed
echo /var/run/distccd/
echo /var/lib/module-rebuild
echo /var/lib/module-rebuild/moduledb
echo /var/lib/module-rebuild/moduledbe
echo /etc/locale.gen
for locale in `locale -a | grep -v "^C\$" | grep -v "^POSIX\$"`; do
       echo "/usr/lib/locale/$locale"
echo /var/run/ 
echo /var/run/
cruftdir /var/lib/jboss
cruftdir /var/cache/jboss


Alternative, smaller version

If you don't want to clean your whole system but just check the /etc/ directory for orphaned files you might be interested in this slightly shorter script.

# This script tries to find orphaned files in /etc
# based upon the information from portage.
# by Phillip 'Firebird' Berndt
import sys, glob, re, os, os.path
staticProtections = [
	"/etc/config-archive", "/etc/passwd", "/etc/shadow",
	"/etc/runlevels", "/etc/group", "/etc/gshadow",
	"/etc/make.conf", "/etc/make.profile", "/etc/magic",
	"/etc/ssl", "/etc/runlevels", "/etc/ssl", "/etc/gtk",
	"/etc/env.d", "/etc/portage", "/etc/gconf"

sys.stderr.write("Creating list of protected files\n")
protectedFiles = ["/etc"]
for fileList in glob.glob("/var/db/pkg/*/*/CONTENTS"):
	for file in open(fileList).read().split("\n"):
		match = re.match("^(dir|obj) (/etc/[^ ]+)", file)
		if match: protectedFiles.append(
sys.stderr.write("Comparing against files in /etc/\n")
def checkFile(file):
	if file in protectedFiles: return False
	for other in staticProtections:
		if file.find(other) == 0: return False
	return True
for file in os.popen("find /etc").read().split("\n"):
	if checkFile(file): print file
Retrieved from ""

Last modified: Sun, 14 Sep 2008 17:47:00 +0000 Hits: 37,537