Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How to to compare owners and permissions of content of two folders? Is there something like diff command which compare recursively two folders and display owner and permissions differences?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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


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.

share|improve this answer

ls -al will show the permissions, if both of them are in the same folder you will get something like this:

drwxr-xr-x 4 root  root 4096 nov 28 20:48 temp
drwxr-xr-x 2 lucas 1002 4096 mrt 24 22:33 temp2

The 3rd column is the owner, the 4th is the group.

share|improve this answer
Umm, what about the contents of temp and temp2? –  cjc Mar 24 '12 at 22:16
two ways: open 2 shells go into both folders and do the same ls -al command, or 1 shell with tmux or just go into one folder do the command go into the other and do the same command again. –  Lucas Kauffman Mar 24 '12 at 22:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.