#!/usr/bin/perl -w ### Must pass full path for directories or with ~/ if ### in home directory use strict; use diagnostics; use File::Find (); @ARGV == 2 or die "Usage: cp-perms \n"; sub cpmod2 ($$) { my @a = (stat shift)[2,4,5]; chown @a[1,2], @_; chmod $a[0] & 07777, @_; } use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; my $correct_dir = $ARGV[0]; my $wrong_dir = $ARGV[1]; my $wanted = sub { $name =~ /\Q($wrong_dir\E)(.*)/ or do { warn "Can't match $name for $wrong_dir in line __LINE__.\n"; return undef; }; my $the_thing = "$correct_dir$2"; if (-e $the_thing) { cpmod2($the_thing,$name) or die "just couldnt do it: $!\n"; } }; File::Find::find({wanted => $wanted}, $wrong_dir);