|
|
Install the Linux rename utility
Here's one that I wrote that has fewer options, but I find it very useful.
It accepts full perl regular expressions as arguments.
#!/usr/bin/perl
# remv: Regular Expression mv
# Usage: remv [-t | -r] filter "regular expression"
# -t is to test regex
# -r is to perform the mv operation
# filter is an argument to ls (ex. *.pl)
# regular expression is put in quotes. $s are backslash \escaped
#
# Example: remv -t \*.jpg "s/oldname(\d)(.jpg)/newname\$1\$2/"
#
$mode = shift;
$filter = shift;
$regex = shift;
$str = "\$file =~ $regex";
chomp($filter);
chomp($regex);
@filelist = `ls $filter`;
if ($mode eq "-r") {
foreach $file (@filelist) {
chomp($file);
$oldname = $file;
eval $str;
print "renaming: $oldname to $file\n";
`mv $oldname $file`;
}
}
elsif ($mode eq "-t") {
foreach $file (@filelist) {
chomp($file);
$oldname = $file;
eval $str;
print "$oldname -> $file\n";
}
}
else { print "-t\ttest regex\n-r\trename files\n";}
So something like:remv -t \*.jpg "s/oldname(\d)(.jpg)/newname\$1\$2/" will rename "oldname1.jpg" and "oldname2.jpg" to "newname1.jpg" and "newname2.jpg" repectively.
Use this one...
One more time. It ate my backslashes.
2nd correction
The backslashes got eaten in the first comment.
On the command line you should type the command like this:
and it will print:
then to actually rename the files use the "-r" switch instead of "-t"
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:Hints1 new Hints in the last 24 hoursComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.08 seconds |
|