[thelist] bulk rename on Mac

Phil Turmel philip at turmel.org
Tue Nov 23 21:57:44 CST 2010


On 11/23/2010 02:44 PM, Hassan Schroeder wrote:
> On Tue, Nov 23, 2010 at 11:20 AM, Joel D Canfield <joel at bizba6.com> wrote:
>> I have a folder packed with .asp files which I need to rename .php (yes, I
>> changed the code inside already)
>>
>> mv *.asp *.php in Terminal seems like it should work, but only throws an
>> error (well, not really, it just spits back "here's how to use mv")
> 
> ripple:/tmp$ ls *.asp
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 1.asp
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 2.asp
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 3.asp
> ripple:/tmp$
> ripple:/tmp$ for arg in *.asp; do echo $arg | sed 's/.asp//'  ; done
> 1
> 2
> 3
> ripple:/tmp$ for arg in *.asp; do mv $arg `echo $arg | sed 's/.asp//'`.php; done
> ripple:/tmp$ ls *.php
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 1.php
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 2.php
> -rw-r--r--  1 hassan  wheel  0 Nov 23 11:41 3.php
> ripple:/tmp$
> 
> Simplistic, hopefully adequate :-)
> 

Good Lord!  sed?  Does the MacOS shell not include the expansion operators % or %% ?

If it does support them, try:

for arg in *.asp ; do mv $arg ${arg%.asp}.php ; done

If it doesn't support them, please accept my condolences.

Phil


More information about the thelist mailing list