Sign up ×
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

3 Answers 3

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 and 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

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:

rync  -n  -rpgov src_dir dst_dir  
(-n is a must in case 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)

share|improve this answer

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.