rsync - sync files modified within the last 60 days
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Maybe the way I went to work on the problem is more complicated than it needs to be. Anyway, I worked around it with an extra step, that is done by a perl script I wrote for the purpose. The script, with the help of find, copies all files from a source directory to a destination directory if they're older than a specified amount of days.
Maybe it will come in handy for somebody else, so I post it here:
Code:
#!/usr/bin/perl
use strict;
use warnings;
use File::Path;
use File::Basename;
use File::Spec;
use File::Copy;
use Cwd;
use Getopt::Long;
# make output unbuffered
$| = 1;
my $path = getcwd;
my $mtime = 1;
my $dest;
my $verbose = '';
my $showhelp = '';
my $result = GetOptions("source=s" => \$path,
"mtime=i" => \$mtime,
"dest=s" => \$dest,
"help" => \$showhelp,
"verbose" => \$verbose);
# DEBUG
# print "\$path = $path\n\$mtime = $mtime\n\$dest = $dest\n\$showhelp = $showhelp\n\$verbose = $verbose\n";
# exit(0);
my $usage = "Usage: $0 --dest <destination-path>\n\t" .
"[--source <source-path> | --mtime <mtime> | --verbose] [--help]\n\t" .
"Type $0 --help for more information.";
my $help = <<EOHELP;
$0 - Copy file hierarchies selectively
based on their modification times
Options:
-s | --source=SourceDir Source path. Default: pwd
-m | --mtime mtime (see man find). Default: 1
-d | --dest=DestDir Destination path. Mandatory option.
-h | --help Print this help screen.
-v | --verbose Be more verbose. Default: false
EOHELP
if ($showhelp) {
print $help;
exit(0);
}
unless ($dest) {
die "$usage\n";
}
# remove trailing slash from $dest
$dest =~ s/\/$//;
my $find = "find $path -type f -mtime -$mtime";
my @files = `$find`;
my %dirs_created;
foreach (@files) {
# debug
print;
chomp;
s/^\.\///;
my ($filename, $directories, $suffix) = fileparse($_);
my $new_dir = File::Spec->canonpath(File::Spec->catdir($dest, $directories));
unless (exists $dirs_created{$new_dir}) {
$dirs_created{$new_dir} = mkpath($new_dir);
print "Created $new_dir\n" if $verbose;
}
copy($_, File::Spec->catfile($new_dir, "$filename$suffix"));
print File::Spec->catfile($new_dir, "$filename$suffix") . "\n" if $verbose;
}
exit(0);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.