$ diff -r test1/ test2/
diff -r test1/common/common.txt test2/common/common.txt
1c1
< This is a common line
---
> This is a common line.
Only in test2/common: common.txt~
Only in test1/: different1
Only in test2/: different2
####
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
sub check_dirs {
die "Please provide 2 Directories!\n" unless ($#ARGV == 1);
for (@_) { die "Input $_ is not a directory!\n" unless (-d $_) };
}
check_dirs(@ARGV);
use File::DirCompare;
# Simple diff -r --brief replacement
use File::Basename;
File::DirCompare->compare($ARGV[0], $ARGV[1], sub {
my ($a, $b) = @_;
if (! $b) {
printf "Only in %s: %s\n", dirname($a), basename($a);
} elsif (! $a) {
printf "Only in %s: %s\n", dirname($b), basename($b);
} else {
print "Files $a and $b differ\n";
}
});
__END__
$ perl cmp.pl test1/ test2/
Files test1/common/common.txt and test2/common/common.txt differ
Only in test2/common: common.txt~
Only in test1: different1
Only in test2: different2
####
#!/usr/bin/perl
use strict;
use warnings;
use Text::Diff;
use File::Dircmp;
use Data::Dumper;
sub check_dirs {
die "Please provide 2 Directories!\n" unless ($#ARGV == 1);
for (@_) { die "Input $_ is not a directory!\n" unless (-d $_) };
}
check_dirs(@ARGV);
my @dircmp = dircmp($ARGV[0], $ARGV[1]);
my @diff;
foreach my $element (@dircmp) {
if ($element =~ /^Files/) {
my @tmp = split / /, $element;
push @diff, diff $tmp[1] => $tmp[3];
}
}
print Dumper \@dircmp if (@dircmp);
print @diff if (@diff);
__END__
$ perl cmp.pl test1/ test2/
$VAR1 = [
'Only in test1/: different1',
'Only in test2/: different2',
'Only in test2//common: common.txt~',
'Files test1//common/common.txt and test2//common/common.txt differ'
];
--- test1//common/common.txt Wed Mar 8 11:41:08 2017
+++ test2//common/common.txt Wed Mar 8 11:44:35 2017
@@ -1 +1 @@
-This is a common line
+This is a common line.