There was a script someone wrote in
another question: find / -type d
-printf "chmod %m %p \n" > reset_perms.sh that forced the
permissions down. I'd like to compare
and output the changes rather than
force them down.
Instead of printing out the commands to run change permissions, simply adjust the printf to spit out the uid, gid, mode, and fullpath and send the output to a file. Then as womble mentioned, use diff to compare the two files.
$find / -printf "%U, %G, %m, %p\n" > permissions.txt
0, 0, 755, /bin
0, 0, 755, /bin/chgrp
0, 0, 755, /bin/tar
0, 0, 755, /bin/dir
0, 0, 777, /bin/sh
0, 0, 777, /bin/pidof
0, 0, 777, /bin/bzless
0, 0, 755, /bin/zgrep
...
I think the best approach here is to look at how you are actually updating the files in DIR2. Rather than comparing them afterwards, use a tool like rsync
to do the copy. For example, in rsync
you can run this command:
rsync -auv --delete /path/to/dir1/* /path/to/dir2/
This will copy all files that are newer in dir1 to dir2 and delete any files which no longer exist in dir1. Basically it's a reliable folder "update" without wasting the time of copying files which are already up to date.
Best Answer
I like to use rsync for this purpose.
For example, on ServerA run:
You can remove the
-c
switch if you don't need to do a checksum comparison of the files. Without it rsync will assume they are the same if they have the same size and timestamps.Note the trailing slashes on each of the paths.
Very important: Make sure you have the
-n
switch otherwise rsync will start changing the contents of ServerB