find-orphans.sh 388 B

123456789101112131415161718
  1. #!/bin/sh
  2. for pkg in $(dpkg --get-selections |\
  3. grep -Ee '[[:space:]]install$' |\
  4. grep -Eoe '^[^[:space:]]+'); do
  5. line="$(apt-cache showpkg "$pkg" | grep '/var/lib/apt/lists/' | head -n1)"
  6. if [ -n "$line" ]; then
  7. file="$(echo "$line" | cut -d'(' -f2 | cut -d')' -f1)"
  8. if [ -r "$file" ]; then
  9. continue
  10. fi
  11. fi
  12. # Found an orphan. Print its name.
  13. echo "$pkg"
  14. done