You're doing a lot of shell programming... the problem is with your system call, shells can be very different accross systems (their syntax can vary), as can ls/cp/mv... and their options
If you were to use File::Find::Rule with Path::Tiny your program gets a little simpler and more portable , like this, using the other AMs renaming idea
#!/usr/bin/perl --
use strict;
use warnings;
use POSIX();
use File::Find::Rule qw/ find rule /;
use Path::Tiny qw/ path /;
my $dir_to_search = 'goner';
print join ' ', "Before move: ", find( file => in => $dir_to_search ,)
+, "\n";
my_move_log_files($dir_to_search);
print join ' ', "After move: ", find( file => in => $dir_to_search ,)
+, "\n";
exit( 0 );
sub my_move_log_files {
my @log_dirs_to_move = @_;
for my $src_dir (@log_dirs_to_move) {
my $dated = "logs_dir".POSIX::strftime('%Y%m%d%H%M%S', localt
+ime );
my $final = path( $src_dir, $dated);
my $temp = path( $src_dir, '..', $dated);
path( $src_dir )->move( $temp );
path( $src_dir )->mkpath;
path( $temp )->move( $final );
}
}
__END__
$ perl file-find-rule-path-tiny-move-rename-goner-assubdir.pl
Before move: goner/touchme.txt
After move: goner/logs_dir20150528161733/touchme.txt