[thelist] bulk rename on Mac

Phil Turmel philip at turmel.org
Tue Nov 23 21:48:25 CST 2010

Hi Joel,

On 11/23/2010 02:20 PM, Joel D Canfield 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")
> what's the obvious thing I'm missing?

No one else seems to have answered that last question, so let me toss this out:

You have intuitively applied a DOS/Windows paradigm in a Unix environment.  In classic DOS and its derivatives, the command interpreter only parsed enough of the command line to figure out what executable to run.  The balance of the command line was passed to the executable.  That makes it both possible and reasonable for each executable to make the "*" wildcard context-sensitive.... it can be a search wildcard in a source parameter, like your "*.asp", and a replacement placeholder in a destination parameter, like your "*.php".  DOS would do some parsing on the executable's behalf to help make this work, but the app would have to search the file system on its own.  The vast majority of DOS tools honor this paradigm, so DOS power users intuitively try this when learning a *nix shell (and grit their teeth in frustration at the hoops they have to jump through when it should 'just work').

But the Unix world and its original shell don't pass the original command line to the executable...  The shell parses the parameters, and the unquoted asterisk is a file search wildcard *in the shell*.  The executable never sees that asterisk, unless no file matches at all.

So your command line was pre-processed by the shell into something like:

mv abc.asp def.asp ghi.asp jkl.asp *.php

and some wiseguy who contributed to the 'mv' source made it toss out a tutorial when it encounters this pattern.

Essentially, every unix app accepts file search wildcards, without having a lick of code for it in the app itself.



More information about the thelist mailing list