Is there a Linux tool like diff that will recursively compare files and directories, but with the addition of also comparing: extended attributes, acl's, se contexts?
-
1The supplied answers work for doing once in a while comparisons. But, they are not adequate for doing these types of comparisons many times an hour when testing software. I might be inclined to modify the diff source code to include these comparisons.– Michael GantzJan 19, 2014 at 23:41
3 Answers
I've done this before using rsync -aHAX --delete
remembering to add the -n
and -i
flags.
This is slightly counterintuitive, but bear with me. The main rsync
command is what you would need to sync the two directories together. But -n -i
causes it NOT to sync (i.e. do a dry run) and just print out what it would have done and why. It isn't fantastic to parse, but you can get the filename out easily and pipe to ls
or similar.
This will look at everything including mtimes, dates etc., as well as not following over on device nodes, sockets, named pipes etc. The command line above looks at ACLs and extended attributes too. You can adjust what you are looking at by changing the options to rsync
, limit it to one device with -x
, change soft & hard link behaviour etc. etc.
janos already said what to do:
find /a -exec stat -c '%A %C %F %g %u %s %Y %n' {} \; >a
find /b -exec stat -c '%A %C %F %g %u %s %Y %n' {} \; >b
diff -u a b
And man 1 stat
says:
%A access rights in human readable form
%C SELinux security context string
%F file type
%g group ID of owner
%u user ID of owner
%s total size, in bytes
%Y time of last modification, seconds since Epoch
%n file name
To compare the file contents you can use:
find -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 33 | cut -c 35-
as described here: http://www.commandlinefu.com/commands/view/3555/find-duplicate-files-based-on-size-first-then-md5-hash
-
This solution does not provide a workable solution. The diff that is displayed is context free and too difficult to read. I'm looking for something that can show me a file name and what is different about it. Not a diff on two finds which is a completely different beast. Jan 16, 2014 at 23:59
-
1GNU
find
has the features of GNUstat
built in (and predates GNU stat by decades). You'll also want to sort the output before diffing. And you need(cd /a && find . ...)
otherwise all the lines will differ because of/a
vs/b
in the file path. Jan 30, 2014 at 9:56
Here's a quick bash script I wrote to compare extended attributes. It prints out every file name, and then any differences in attributes:
cd a
export relpath=[path/to/b/from/a]
for filename in $(find .);
do
echo $filename;
diff <(xattr -l $filename) <(xattr -l $relpath/$filename);
done
Borrowing from another answer, we can modify this to use stat
instead of xattr
:
for filename in $(find .);
do
echo $filename;
diff <(stat -c '%A %C %F %g %u %s %Y' $filename) <(stat -c '%A %C %F %g %u %s %Y' $relpath/$filename);
done