检查 /usr 目录哪些文件不在包管理里 For Arch Linux

当然改改里面的命令也就能用在其他发行版了= =
随手写的, 各种不靠谱勿喷哦><

#!/usr/bin/env python2
import subprocess
import os
from os.path import join

pkg_list = subprocess.check_output(["pacman", "-Q"]).split("\n")[:-1]
pkg_list = map(lambda line:line.split()[0], pkg_list)

file_mapper = {}
for pkg in pkg_list:
    file_list = subprocess.check_output(["pacman", "-Ql", pkg]).split("\n")[:-1]
    file_list = map(lambda line:line.split(" ",1)[1], file_list)
    for filename in file_list:
        file_mapper[filename] = pkg

for root, dirs, files in os.walk('/usr'):
    if "__pycache__" in root:
        continue
    for name in files:
        filename = os.path.join(root, name)
        if filename not in file_mapper:
            if filename.endswith(".pyc") or filename.endswith(".cache"):
                continue
            print filename, "Not Found!"

13 thoughts on “检查 /usr 目录哪些文件不在包管理里 For Arch Linux”

  1. find /usr | sort -u >a.txt

    pacman -Qlq $(pacman -Qq) >b.txt

    diff a.txt b.txt

    而且能顺带检查有没有软件包标记有的而文件系统里面没有的。命令超级简单!

    1. 1. 关于 subprocess.call, 因为文档上不建议把它和PIPE一起用, 所以我一直用的Popen

      2. 谢谢, 已修改^_^

    1. 唔, 那是因为我用bash写dict和字符串操作总是有一种想一头撞死的赶脚…
      于是还是球各种大大改写成bash吧 ^^

        1. find /usr | sort -u >a.txt
          pacman -Qlq $(pacman -Qq) >b.txt
          diff a.txt b.txt
          而且能顺带检查有没有软件包标记有的而文件系统里面没有的。命令超级简单!

          1. 抱歉我发了两个回复,但是还是再发一遍吧:
            修正:

            find /usr | sort -u >a.txt
            pacman -Qlq $(pacman -Qq) | sort -u >b.txt
            diff a.txt b.txt

            据我估计,耗时应该很长。

Leave a Reply

Your email address will not be published. Required fields are marked *

QR Code Business Card