Comparing owners and permissions of content of two folders?

Solution 1:

The solution, as with all things, is a perl script:

#!/usr/bin/perl

use File::Find;

my $directory1 = '/tmp/temp1';
my $directory2 = '/tmp/temp2';

find(\&hashfiles, $directory1);

sub hashfiles {
  my $file1 = $File::Find::name;
  (my $file2 = $file1) =~ s/^$directory1/$directory2/;

  my $mode1 = (stat($file1))[2] ;
  my $mode2 = (stat($file2))[2] ;

  my $uid1 = (stat($file1))[4] ;
  my $uid2 = (stat($file2))[4] ;

  print "Permissions for $file1 and $file2 are not the same\n" if ( $mode1 != $mode2 );
  print "Ownership for $file1 and $file2 are not the same\n" if ( $uid1 != $uid2 );
}

Look at http://perldoc.perl.org/functions/stat.html and http://perldoc.perl.org/File/Find.html for more info, particularly the stat one if you want to compare other file attributes.

If files don't exist in directory2 but exist in directory1, there will also be output because the stat will be different.

Solution 2:

Find and stat:

find . -exec stat --format='%n %A %U %G' {} \; | sort > listing

Run that in both directories then compare the two listing files.

Saves you from the evils of Perl...

Solution 3:

Do you make sure the 2 folders should be the same recursively to some extent? I think the rsync command is very powerful for that.

In your case you may run:

rsync  -n  -rpgov src_dir dst_dir  
(-n is a must otherwise dst_dir will be modified )

The different files or folders will be listed as the command output.

You can see the man rsync for a more complete explanation of these options.