Find the answer to your Linux question:
Results 1 to 6 of 6
mv *.php.new *.php doesn't give the result I want - all files ending in php.new renamed with same name and ending .php. What's the easiest way to do it? Thanks ...
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5

    renaming lots of files

    mv *.php.new *.php
    doesn't give the result I want - all files ending in php.new renamed with same name and ending .php. What's the easiest way to do it?
    Thanks
    Tony

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Correct. The "mv" command takes a list of current files and a single destination. If that destination is a directory, they are moved into the directory; otherwise, they are simply renamed to that last argument. It can be dangerous .

    What you actually want is the rename command:
    rename(1): Rename files - Linux man page

    In your particular instance:
    Code:
    rename .php.new .php *.php.new
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5
    Cabhan:
    Thanks. Can't see what I'm doing wrong:

    rename .php.new .php *.php.new
    syntax error at (eval 1) line 1, near "."
    Tony

  4. #4
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    1,939
    The command cabhan suggested works. You need a space after the second php and before the asteerisk (*) which it doesn't look like you have in your post and would make sense with the error message you posted.

  5. #5
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Ah. There are two versions of the "rename" command out there: you may have the other one. Run the command:
    Code:
    man rename
    from the terminal, and you'll see the man page for yours. It may talk about using a Perl regular expression: that's the other version of rename. For that one, the command would be:
    Code:
    rename 's/\.php\.new/.php/' *.php.new
    On the other hand, if it's the same rename that I posted earlier, I don't know what to tell you <_<.
    DISTRO=Arch
    Registered Linux User #388732

  6. #6
    Just Joined!
    Join Date
    Jun 2010
    Posts
    5
    Quote Originally Posted by Cabhan View Post
    Ah. There are two versions of the "rename" command out there: you may have the other one. Run the command:
    Code:
    man rename
    from the terminal, and you'll see the man page for yours. It may talk about using a Perl regular expression: that's the other version of rename. For that one, the command would be:
    Code:
    rename 's/\.php\.new/.php/' *.php.new
    On the other hand, if it's the same rename that I posted earlier, I don't know what to tell you <_<.
    THat's solved it. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...