Renaming files in Linux using perl scripting
4
votes
3
answers
1668
views
I have a set of files with prefix, say "pre_", on a Linux machine and I just want to rename all of these files by removing that. Here is the perl code I wrote it doesn't throw any errors, but the work is not done.
#!/usr/bin/perl -w
my @files =
ls -1 | grep -i \"pre_.*\"
;
foreach $file ( @files )
{
my @names = split(/pre_/, $file);
my $var1 = $names;
'mv "$file" "$var1"';
}
Asked by Sasi Pavan
(51 rep)
Aug 9, 2023, 06:51 AM
Last activity: Aug 10, 2023, 05:59 AM
Last activity: Aug 10, 2023, 05:59 AM