Comparing owners and permissions of content of two folders?
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?
The solution, as with all things, is a perl script:
#!/usr/bin/perluse 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.
Check more discussion of this question.
No related posts.
Leave a comment
Recent Posts
- SCP transfer only modified files
- How can I automate clearing and resetting a Linux user’s home directory to a default?
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





