Findcruft
From Gentoo Linux Wiki
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
[edit] What is Cruft?
"Over time, any system builds up cruft."
Redmond concerned anonymous
- Cruft
- 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.
[edit] Install findcruft
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 wget http://ifp.loeber1.de/findcruft-ebuild.tar.bz2 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
[edit] 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.
[edit] 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.
[edit] 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 |
#!/usr/bin/perl
scalar(@ARGV) == 2 or die "Usage: mvcruft cruftfile backupdir\n";
open FILELIST, "$ARGV[0]" or die "Cannot open cruft file: $ARGV[0]\n";
$CRUFTDIR="$ARGV[1]";
while(<FILELIST>)
{
/(.*\/)(.*)/;
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
[edit] Deleting the Cruft
root# xargs rm -rf < cruft.out
| Explanation: |
|
xargs executes the following command, taking the output from stdin as arguments rm -rf recursively deletes folders and files. |
[edit] Re-run the Script
root# rm cruft.out
Re-run the script to make sure everything was removed that you want to be.
[edit] 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.
[edit] False Positives rules needed
You can here add your false positives:
- To exclude by default:
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
- app-admin/eselect
echo /etc/profile.csh echo /etc/eselect/ld-mtimedb
- app-admin/eselect-wxwidgets
cruftdir /var/lib/wxwidgets
- app-admin/metalog
echo /var/run/metalog.pid
- app-emulation/vmware-workstation
echo /usr/bin/vmware
- app-misc/beagle
cruftdir /var/lib/cache/beagle/indexes cruftdir /var/lib/cache/beagle
- app-misc/uptimed
echo /var/spool/uptimed/bootid echo /var/spool/uptimed/records
- app-office/abiword
echo /usr/bin/abiword
- app-portage/eix
echo /var/cache/eix
- app-portage/kuroo
cruftdir /var/cache/kuroo
- app-shells/bash
echo /usr/bin/bash
- app-text/docbook-xml-dtd
cruftdir /etc/sgml
- app-text/tetex
cruftdir /var/lib/texmf
- dev-db/mysql
echo /var/run/svc-started-mysqld
- dev-db/phpmyadmin
echo /var/db/webapps/phpmyadmin
- dev-libs/openssl
cruftdir /etc/ssl/certs
- media-video/nvidia-glx
echo /usr/lib/libGLcore.so echo /usr/lib/xorg/modules/extensions/libglx.so
- net-fs/samba
echo /etc/samba/smb.conf
- net-misc/dhcp
cruftdir /var/lib/dhcp
- net-misc/ntp
echo /etc/ntp.conf echo /var/run/ntpd.pid
- net-misc/rsync
echo /var/run/rsyncd.pid
- net-misc/tor
echo /etc/tor/torrcecho
- net-proxy/squid
cruftdir /var/cache/squid
- sci-misc/boinc
cruftdir /var/lib/boinc
- sys-apps/dbus
echo /var/lib/dbus/machine-id echo /var/run/dbus/system_bus_socket
- sys-apps/hal
echo /var/run/hald.pid echo /var/lib/cache/hald/fdi-cache
- sys-apps/sed
echo /usr/bin/sed
- sys-devel/distcc
echo /var/run/distccd/distccd.pid
- sys-kernel/module-rebuild
echo /var/lib/module-rebuild echo /var/lib/module-rebuild/moduledb echo /var/lib/module-rebuild/moduledbe
- sys-libs/glibc
echo /etc/locale.gen
for locale in `locale -a | grep -v "^C\$" | grep -v "^POSIX\$"`; do
echo "/usr/lib/locale/$locale"
done
- sys-libs/gpm
echo /var/run/gpm.pid
- sys-process/at
echo /var/run/atd.pid
- www-servers/jboss
cruftdir /var/lib/jboss cruftdir /var/cache/jboss
[edit] Notes
- Original script is here: http://catmur.co.uk/~ed/main/my-bin/cruft
- More scripts by Ed Catmur: http://catmur.co.uk/~ed/main/my-bin/
- Original forum post: http://forums.gentoo.org/viewtopic.php?t=152618
- findcruft forum post: http://forums.gentoo.org/viewtopic.php?t=254197
[edit] 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.
#!/usr/bin/python
# 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(match.group(2))
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
