Start Blogaria Bored bsgen cconf Cookies CopyForward CyclicLog Dialwhatever DNSBalancer fch HammerServer jpeginfo kalk Lectures Microproxy msc Nasapics PGPkey SafeEdit Simple listserv Wallpapers
A little movie
An animation can't be properly rendered. You have probably a too old version of Flash player. |
CopyforwardNewer versions of unix "cp" support the flag "-n", which copies files, but doesn't overwrite recent enough versions. Well, that's newer versions of "cp". For the systems that lack this, here's a small script. Used as "cp", but named "cpf". The listing is below - it can also be downloaded (which might be a newer version, who knows?)
#!/usr/bin/perl
use strict;
usage() if ($#ARGV < 1);
if (-d $ARGV[$#ARGV]) {
for (my $i = 0; $i < $#ARGV; $i++) {
my $src = $ARGV[$i];
$src =~ s{.*/}{};
cpf ($ARGV[$i], $ARGV[$#ARGV] . '/' . $src);
}
} else {
usage() if ($#ARGV != 1);
cpf ($ARGV[0], $ARGV[1]);
}
sub usage() {
die <<"ENDUSAGE";
This is cpf, "copy-forward" utility. Usage is similar to "cp", but doesn't
overwrite recent-enough copies. Written by Karel Kubat, http://www.kubat.nl.
Use at your own risk and for your own pleasure.
cpf srcfile dstfile - copy src to dst, if it's more recent
cpf file file file dstdir - copy files to dstdir, if they are more recent
ENDUSAGE
}
sub cpf($$) {
my $src = shift;
my $dst = shift;
$src =~ s{//}{/}g;
$dst =~ s{//}{/}g;
die ("cpf: No such file $src\n") unless (-f $src);
if (-f $dst and (stat($src))[9] <= (stat($dst))[9]) {
print ("cpf: $src skipped\n");
return;
}
print ("cpf: $src -> $dst\n");
open (my $if, $src) or die ("cpf: cannot read $src: $!\n");
binmode($if);
open (my $of, ">$dst") or die ("cpf: cannot write $dst: $!\n");
binmode($of);
my ($buf, $n);
while ($n = sysread($if, $buf, 10240)) {
die ("cpf: incomplete write to $dst\n")
if (syswrite($of, $buf, $n) != $n);
}
close($if);
close($of);
chmod((stat($src))[2], $dst);
}
|