Suppose that, on a UNIX system, I have a directory that contains the files abc.css, abc.js, and abc.html. In the console, is there a command that I can run that will rename the files to xyz.css, xyz.js, and xyz.html, respectively?

The solution that I'm envisioning is some combination of mv and a regular expression, but I'm not sure exactly how to combine the two.


On Linux the rename command will work:

rename abc xyz "abc.*"

| improve this answer | |

What OS?

In Windows you don’t need regular expressions. A simple wildcard should suffice:

>ren abc.* xyz.*
| improve this answer | |
  • For some reason, that didn't work for me. It gave me the typical "usage: mv ..." error response that it gives when the command syntax is incorrect. – zeptonaut Feb 13 '12 at 3:58
  • What OS?​​​​​​​ – Synetech Feb 13 '12 at 4:06
  • What? No, that will get expanded to mv abc.css abc.js abc.html xyz.css xyz.js xyz.html. Have you tested this? – Christian Mann Feb 13 '12 at 5:46
  • @ChristianMann, yes I did and it worked as expected in Windows. – Synetech Feb 13 '12 at 6:01
  • mv isn't a command in cmd.exe. Are you in PowerShell, Cygwin, or an SSH connection to a Linux box? – Christian Mann Feb 13 '12 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.