Используя Perl с модулем File :: Find вы можете реализовать что-то вроде этого:
use File::Find;
my $dirname = "../test/";
finddepth(sub {
return if /^\.{1,2}$/; # ignore '.' and '..'
return unless -d $File::Find::name; # check if file is directory
if (s/\ /_/g) { # replace spaces in filename with underscores
my $new_name = $File::Find::dir.'/'.$_; # new filename with path
if (rename($File::Find::name => $new_name)) {
printf "Directory '%s' has been renamed to '%s'\n",
$File::Find::name,
$new_name;
} else {
printf "Can't rename directory '%s' to '%s'. Error[%d]: %s\n",
$File::Find::name,
$new_name,
$!, $!;
}
}
}, $dirname);
До:
% tree test
test
├── test 1
├── test 2
└── test 3
└── test 3 4
После:
% tree test
test
├── test_1
├── test_2
└── test_3
└── test_3_4