#!/usr/bin/perl # # upgrade thatdir [thisdir] # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# # This scans thisdir (. by default), and for each file found, checks # # to see whether the corresponding file in thatdir exists and is # # newer. If so, the one in thatdir is copied over the one in thisdir. # # Note that the direction of copy is thatdir -> thisdir; this is the # # same order that the cp/mv/ln and the cptree/lntree commands use. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# $usage = "$0: thatdir [thisdir]\n"; $thatdir = $ARGV[0] || die $usage; $thisdir = $ARGV[1] || '.'; open(F,"find $thisdir -type f -print |") || die "$0: Can't run find command.\n"; while ($f = ) { chop $f; $f =~ s#^$thisdir/##; $thisfile = "$thisdir/$f"; $thatfile = "$thatdir/$f"; if ( -f "$thatfile") { @thatstat = stat("$thatfile"); @thisstat = stat("$thisfile"); # Missing files get zeroes. $thattime = $thatstat[9]; $thistime = $thisstat[9]; if ($thattime > $thistime) { print "$thatfile $thattime newer than $thisfile $thistime\n"; system "Cp $thatfile $thisfile"; # } else { # print "$thatfile $thattime older than $thisfile $thistime\n"; } } }