<分区>
给定 centos 中的 2 个文件夹:/folder1 和/folder2,每个文件夹中都有一些文件和子文件夹。
我用beyond compare 3来比较内容,但不知道如何同时比较文件模式和所有者。
感谢您的帮助!
标签 linux
<分区>
给定 centos 中的 2 个文件夹:/folder1 和/folder2,每个文件夹中都有一些文件和子文件夹。
我用beyond compare 3来比较内容,但不知道如何同时比较文件模式和所有者。
感谢您的帮助!
最佳答案
如果不需要一次全部完成,您可以先diff <(cd /folder1; ls -lR) <(cd /folder2; ls -lR) | grep '^[<>]'
获取所有者/模式差异,然后 diff -r /folder1 /folder2
获取内容差异。
如果您真的希望一次性完成,您可以为每个目录生成一个列表,包括名称、所有者、模式和校验和,然后比较两者。不过,这只会告诉您哪些文件不同,而不会告诉您它们有什么变化。
diff \
<(find /folder1 -printf '%P\t%u:%g\t%M' \( \
-type b -exec stat -c '\tb:%t:%T\n' -- '{}' \; -o \
-type c -exec stat -c '\tc:%t:%T\n' -- '{}' \; -o \
-type d -printf '/\n' -o \
-type p -printf '|\n' -o \
-type f -printf '\t' -exec sum -- '{}' \; -o \
-type l -printf '\t-> %l\n' -o \
-type s -printf '=\n' -o \
-printf '\t???\n' \) | sort) \
<(find /folder2 -printf '%P\t%u:%g\t%M' \( \
-type b -exec stat -c '\tb:%t:%T\n' -- '{}' \; -o \
-type c -exec stat -c '\tc:%t:%T\n' -- '{}' \; -o \
-type d -printf '/\n' -o \
-type p -printf '|\n' -o \
-type f -printf '\t' -exec sum -- '{}' \; -o \
-type l -printf '\t-> %l\n' -o \
-type s -printf '=\n' -o \
-printf '\t???\n' \) | sort) | \
grep '^[<>]'
关于linux - 如何比较 2 个 linux 文件夹的内容和模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43670179/