[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] how to bulk rename files
From: |
Steven W. Orr |
Subject: |
Re: [Help-bash] how to bulk rename files |
Date: |
Wed, 11 Apr 2012 17:07:01 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20 |
On 4/11/2012 4:44 PM, address@hidden wrote:
I have many files, 2.5 million, that I have to make available to Windows folks
They demand that the files have a extension added
Is there an efficient method of bulk renaming files
Richard
I know this is probably inappropriate, but my fave is in perl.
#!/usr/bin/perl
$op = shift;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
This allows you to do things like
rename 's/$/.sav' *
or
find . -type f -print0 | xargs -0 rename 's/$/.sav/'
but you can also do cool things like
rename 'tr/A-Z/a-z' *
to cause all filenames to be lowercase
The corresponding big brother to this is replace_str
#! /usr/bin/perl -i.old
$from_text = shift ;
$to_text = shift ;
while( <> ) {
s/$from_text/$to_text/g ;
print ;
}
I promise never to inflict this on a bash list again. :-)
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
- Re: [Help-bash] how to bulk rename files, (continued)
- Re: [Help-bash] how to bulk rename files, DJ Mills, 2012/04/11
- Re: [Help-bash] how to bulk rename files, Clark Wang, 2012/04/12
- Re: [Help-bash] how to bulk rename files, Greg Wooledge, 2012/04/12
- Re: [Help-bash] how to bulk rename files, Stephane Chazelas, 2012/04/12
- Re: [Help-bash] how to bulk rename files, Greg Wooledge, 2012/04/12
- Re: [Help-bash] how to bulk rename files, lxnf98mm, 2012/04/12
- Re: [Help-bash] how to bulk rename files, Chet Ramey, 2012/04/12
Re: [Help-bash] how to bulk rename files, DJ Mills, 2012/04/11
Re: [Help-bash] how to bulk rename files,
Steven W. Orr <=
Re: [Help-bash] how to bulk rename files, Conrad J. Sabatier, 2012/04/22
Re: [Help-bash] how to bulk rename files, DJ Mills, 2012/04/12