linux – 比较两个文件夹内容的所有者和权限?

如何比较两个文件内容的所有者和权限?是否有类似diff命令的东西,它递归地比较两个文件夹并显示所有者和权限差异?

解决方法

与所有事情一样,解决方案是perl脚本:
#!/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 );
}

有关详细信息,请查看http://perldoc.perl.org/functions/stat.htmlhttp://perldoc.perl.org/File/Find.html,特别是如果要比较其他文件属性,请查看统计信息.

如果directory2中不存在文件但存在于directory1中,则还会输出,因为统计信息将不同.

相关文章

insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...