Here is a simple script that you can use. I like to use the non-standard File::chdir module to control the cd control operations, so to use this script as-it you will need to install it ( sudo cpan File::chdir ).
#!/usr/bin/perl use strict; use warnings; use File::Copy; use File::chdir; # allows cd-ing by use of $CWD, much easier but needs CPAN module die "Usage: $0 dir prefix" unless (@ARGV >= 2); my ($dir, $pre) = @ARGV; opendir(my $dir_handle, $dir) or die "Cannot open directory $dir"; my @files = readdir($dir_handle); close($dir_handle); $CWD = $dir; # cd to the directory, needs File::chdir foreach my $file (@files) { next if ($file =~ /^\.+$/); # avoid folders . and .. next if ($0 =~ /$file/); # avoid moving this script if it is in the directory move($file, $pre . $file) or warn "Cannot rename file $file: $!"; }
Joel Berger Jan 25 2018-11-11T00: 00Z
source share