要在Perl或shell中非递归地迁移目录,可以使用以下方法:
use File::Copy;
my $source_dir = "/path/to/source";
my $destination_dir = "/path/to/destination";
opendir(my $dh, $source_dir) or die "Can't open directory: $!";
while (my $file = readdir($dh)) {
next if $file =~ /^\.\.?$/; # Skip . and ..
move("$source_dir/$file", "$destination_dir/$file") or die "Can't move file: $!";
}
closedir($dh);
source_dir="/path/to/source"
destination_dir="/path/to/destination"
for file in "$source_dir"/*; do
if [ -f "$file" ]; then
mv "$file" "$destination_dir"
fi
done
这些方法将非递归地将源目录中的所有文件移动到目标目录。如果需要移动子目录,请使用递归方法。
领取专属 10元无门槛券
手把手带您无忧上云