Difference between revisions of "Lostfiles"

From ArchWiki
Jump to: navigation, search
(added additional false positives and ended by piping into less)
m (Script source: wrapped in proper formatting and removed version which is silly for a wiki script without vc)
Line 5: Line 5:
  
 
== Script source ==
 
== Script source ==
 +
{{hc|/usr/local/bin/lostfiles|<nowiki>
 +
#!/bin/bash
  
#!/bin/bash
+
# License: GPL v2.0 http://www.gnu.org/licenses/gpl.html
+
 
# LostFiles v0.2
+
# Initially scripted by the Arch Linux Community
# License: GPL v2.0 http://www.gnu.org/licenses/gpl.html
+
# Mircea Bardac (dev AT mircea.bardac.net)
+
# http://mircea.bardac.net/
# Initially scripted by the Arch Linux Community
+
# Modified by Jan Janssen
# Mircea Bardac (dev AT mircea.bardac.net)
+
 
# http://mircea.bardac.net/
+
# Description:
# Modified by Jan Janssen
+
# Search for files which are not part of installed Arch Linux packages
+
 
# Description:
+
# Usage:
# Search for files which are not part of installed Arch Linux packages
+
#  lostfiles
+
 
# Usage:
+
if [ $UID != "0" ]; then
#  lostfiles > changes
+
  echo "You must run this script as root." 1>&2
# changes is a file containing a list of added/removed files
+
  exit 1
+
fi
if [ $UID != "0" ]; then
+
 
        echo "You must run this script as root." 1>&2
+
comm -13 \
        exit
+
  <(pacman -Qlq | sed -e 's|/$||' | sort -u) \
fi
+
  <(find / -not \( \
comm -13 \
+
  -wholename '/boot/grub' -prune -o \
<(pacman -Qlq | sed -e 's|/$||' | sort -u) \
+
  -wholename '/dev' -prune -o \
<(find / -not \( \
+
  -wholename '/etc/conf.d' -prune -o \
                -wholename '/boot/grub' -prune -o \
+
  -wholename '/etc/ssh' -prune -o \
-wholename '/dev' -prune -o \
+
  -wholename '/etc/ssl' -prune -o \
                -wholename '/etc/conf.d' -prune -o \
+
  -wholename '/etc/systemd/system' -prune -o \
-wholename '/etc/ssh' -prune -o \
+
  -wholename '/home' -prune -o \
-wholename '/etc/ssl' -prune -o \
+
  -wholename '/lost+found' -prune -o \
-wholename '/etc/systemd/system' -prune -o \
+
  -wholename '/media' -prune -o \
-wholename '/home' -prune -o \
+
  -wholename '/mnt' -prune -o \
-wholename '/lost+found' -prune -o \
+
  -wholename '/proc' -prune -o \
-wholename '/media' -prune -o \
+
  -wholename '/root' -prune -o \
-wholename '/mnt' -prune -o \
+
  -wholename '/run' -prune -o \
-wholename '/proc' -prune -o \
+
  -wholename '/scratch' -prune -o \
-wholename '/root' -prune -o \
+
  -wholename '/sys' -prune -o \
-wholename '/run' -prune -o \
+
  -wholename '/tmp' -prune -o \
-wholename '/sys' -prune -o \
+
  -wholename '/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack' -prune -o \
-wholename '/tmp' -prune -o \
+
  -wholename '/usr/local/bin' -prune -o \
-wholename '/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack' -prune -o \
+
  -wholename '/usr/share/mime/application' -prune -o \
-wholename '/usr/local/bin' -prune -o \
+
  -wholename '/usr/share/mime/audio' -prune -o \
-wholename '/usr/share/mime/application' -prune -o \
+
  -wholename '/usr/share/mime/image' -prune -o \
-wholename '/usr/share/mime/audio' -prune -o \
+
  -wholename '/usr/share/mime/inode' -prune -o \
-wholename '/usr/share/mime/image' -prune -o \
+
  -wholename '/usr/share/mime/interface' -prune -o \
-wholename '/usr/share/mime/inode' -prune -o \
+
  -wholename '/usr/share/mime/message' -prune -o \
-wholename '/usr/share/mime/interface' -prune -o \
+
  -wholename '/usr/share/mime/multipart' -prune -o \
-wholename '/usr/share/mime/message' -prune -o \
+
  -wholename '/usr/share/mime/text' -prune -o \
-wholename '/usr/share/mime/multipart' -prune -o \
+
  -wholename '/usr/share/mime/uri' -prune -o \
-wholename '/usr/share/mime/text' -prune -o \
+
  -wholename '/usr/share/mime/video' -prune -o \
-wholename '/usr/share/mime/uri' -prune -o \
+
  -wholename '/usr/share/mime/x-content' -prune -o \
-wholename '/usr/share/mime/video' -prune -o \
+
  -wholename '/var/abs' -prune -o \
-wholename '/usr/share/mime/x-content' -prune -o \
+
  -wholename '/var/cache' -prune -o \
-wholename '/var/abs' -prune -o \
+
  -wholename '/var/lock' -prune -o \
-wholename '/var/cache' -prune -o \
+
  -wholename '/var/log' -prune -o \
-wholename '/var/lock' -prune -o \
+
  -wholename '/var/lib/pacman' -prune -o \
-wholename '/var/log' -prune -o \
+
  -wholename '/var/run' -prune -o \
-wholename '/var/lib/pacman' -prune -o \
+
  -wholename '/var/spool' -prune -o \
-wholename '/var/run' -prune -o \
+
  -wholename '/var/tmp' -prune \) | sort -u \
-wholename '/var/spool' -prune -o \
+
  ) | sed -e 's|^\t||;' | less
-wholename '/var/tmp' -prune \) | sort -u \
+
 
) | sed -e 's|^\t||;' | less
+
# vim:set ts=2 sw=2 et:
 +
</nowiki>}}

Revision as of 15:18, 23 October 2013

Lostfiles is a script for detecting orphaned files (files which are not owned by any Arch Linux packages).

The script ignores by default a series of directories where packages should not install files. Some files might appear as removed if they're placed in those directories which are not checked.

Script source

/usr/local/bin/lostfiles
#!/bin/bash

# License: GPL v2.0 http://www.gnu.org/licenses/gpl.html

# Initially scripted by the Arch Linux Community
# Mircea Bardac (dev AT mircea.bardac.net)
# http://mircea.bardac.net/
# Modified by Jan Janssen

# Description:
# Search for files which are not part of installed Arch Linux packages

# Usage:
#  lostfiles

if [ $UID != "0" ]; then
  echo "You must run this script as root." 1>&2
  exit 1
fi

comm -13 \
  <(pacman -Qlq | sed -e 's|/$||' | sort -u) \
  <(find / -not \( \
  -wholename '/boot/grub' -prune -o \
  -wholename '/dev' -prune -o \
  -wholename '/etc/conf.d' -prune -o \
  -wholename '/etc/ssh' -prune -o \
  -wholename '/etc/ssl' -prune -o \
  -wholename '/etc/systemd/system' -prune -o \
  -wholename '/home' -prune -o \
  -wholename '/lost+found' -prune -o \
  -wholename '/media' -prune -o \
  -wholename '/mnt' -prune -o \
  -wholename '/proc' -prune -o \
  -wholename '/root' -prune -o \
  -wholename '/run' -prune -o \
  -wholename '/scratch' -prune -o \
  -wholename '/sys' -prune -o \
  -wholename '/tmp' -prune -o \
  -wholename '/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack' -prune -o \
  -wholename '/usr/local/bin' -prune -o \
  -wholename '/usr/share/mime/application' -prune -o \
  -wholename '/usr/share/mime/audio' -prune -o \
  -wholename '/usr/share/mime/image' -prune -o \
  -wholename '/usr/share/mime/inode' -prune -o \
  -wholename '/usr/share/mime/interface' -prune -o \
  -wholename '/usr/share/mime/message' -prune -o \
  -wholename '/usr/share/mime/multipart' -prune -o \
  -wholename '/usr/share/mime/text' -prune -o \
  -wholename '/usr/share/mime/uri' -prune -o \
  -wholename '/usr/share/mime/video' -prune -o \
  -wholename '/usr/share/mime/x-content' -prune -o \
  -wholename '/var/abs' -prune -o \
  -wholename '/var/cache' -prune -o \
  -wholename '/var/lock' -prune -o \
  -wholename '/var/log' -prune -o \
  -wholename '/var/lib/pacman' -prune -o \
  -wholename '/var/run' -prune -o \
  -wholename '/var/spool' -prune -o \
  -wholename '/var/tmp' -prune \) | sort -u \
  ) | sed -e 's|^\t||;' | less

# vim:set ts=2 sw=2 et: