2

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.

2 Answers 2

1

On Linux the rename command will work:

rename abc xyz "abc.*"

1

What OS?

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

>ren abc.* xyz.*
7
  • 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, 2012 at 3:58
  • What OS?​​​​​​​
    – Synetech
    Feb 13, 2012 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? Feb 13, 2012 at 5:46
  • @ChristianMann, yes I did and it worked as expected in Windows.
    – Synetech
    Feb 13, 2012 at 6:01
  • mv isn't a command in cmd.exe. Are you in PowerShell, Cygwin, or an SSH connection to a Linux box? Feb 13, 2012 at 7:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .