[prog] Perl and find(1)
Jacinta Richardson
jarich at perltraining.com.au
Mon Dec 11 06:23:45 UTC 2006
Chris Henderson wrote:
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use diagnostics;
>
> my @directories = qw(
> /home/backup/server1
> /home/backup/server2
> /home/backup/server3
> );
>
> system "find @directories -atime +14 -name \"*.tgz\" -print -exec ls -al
> {} \;";
Another answer. If you do wish to use system, you may also find it better
(security wise) to use the multi-arg version of system, as that does not go past
the shell:
system("find",
@directories,
qw(-atime +14 -name "*.tgz" -print -exec ls -al {} ;)
);
This will save you from having to escape shell meta characters yourself. It
also means that if your directories may contain unsafe characters, that this is
handled correctly.
All the best,
J
More information about the Programming
mailing list