Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: "rename" command is not working

  1. #1

    Default "rename" command is not working

    When I run:

    Code:
    rename -v 's/image/img/g' *.png
    It returns without changing any of the files (which are there - I checked with "ls") and no errors reported. What could be wrong?

  2. #2
    Join Date
    Aug 2008
    Location
    Seattle, WA
    Posts
    1,376

    Default Re: "rename" command is not working

    Quote Originally Posted by 6tr6tr View Post
    When I run:

    Code:
    rename -v 's/image/img/g' *.png
    It returns without changing any of the files (which are there - I checked with "ls") and no errors reported. What could be wrong?
    Why don't you show what the output of ls is? The usage of rename is

    Code:
    rename [options] expression replacement files
    This will replace "expression" by "replacement." Can you tell more about what you're trying to do?

  3. #3

    Default Re: "rename" command is not working

    What you probably want, based on your regex (rename doesn't use regexes
    like that I do not think), is the following:

    Code:
    --------------------
    rename 'image' 'img' *.png
    --------------------

    and that will change things like these:

    'image name here.png'
    'some dumb image.png'
    imageur.png

    to theseL

    'img name here.png'
    'some dumb img.png'
    imgur.png

    Good luck.

  4. #4
    Join Date
    Nov 2009
    Location
    West Virginia Sector 13
    Posts
    15,769

    Default Re: "rename" command is not working

    or you could use the mv command

  5. #5
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    17,079

    Default Re: "rename" command is not working

    On Wed, 02 Oct 2013 23:36:03 +0000, gogalthorp wrote:

    > or you could use the mv command


    That's not quite as effective when it's just a partial rename. I'm not
    even sure how you'd do that without a for loop and some text processing...

    Jim



    --
    Jim Henderson
    openSUSE Forums Administrator
    Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

  6. #6

    Default Re: "rename" command is not working

    Exactly... 'mv' is great at renaming one file, or moving many files to one
    new directory, but it has no ability to rename many files in-place like
    'rename' without a bunch of other hacking (loops as Jim suggests, and
    probably a bit of work with variables and 'sed').

    Good luck.

  7. #7
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,470
    Blog Entries
    2

    Default Re: "rename" command is not working

    Quote Originally Posted by 6tr6tr View Post
    When I run:

    Code:
    rename -v 's/image/img/g' *.png
    It returns without changing any of the files (which are there - I checked with "ls") and no errors reported. What could be wrong?
    To my eye, your command only attempts to "rename" any file named g which is unlikely so of course your command fails.

    You'll probably need to add a Regular Expression wildcard if you want to rename files starting with g, or a forward slash and wildcard if the "g" is a folder name.

    And, as others have noted, "rename" is not typically supported as a BASH command, you will likely want to use "mv" instead.
    Code:
    mv s/image/img/g/* *.png
    HTH,
    TSU

  8. #8

    Default Re: "rename" command is not working

    Quote Originally Posted by tsu2 View Post
    To my eye, your command only attempts to "rename" any file named g which is unlikely so of course your command fails.
    What he wrote is no pathname, but a sed-style replacement expression.
    He wants to replace the string "image" with "img" in all *.png file names AFAIUI.

    And, as others have noted, "rename" is not typically supported as a BASH command, you will likely want to use "mv" instead.
    Of course "rename" is no BASH command, just like "mv" is not.
    But both are standard (on openSUSE at least) LINUX commands:
    Code:
    # rpm -qf /usr/bin/rename
    util-linux-2.21.2-10.2.1.x86_64
    # rpm -qf /usr/bin/mv
    coreutils-8.17-6.2.1.x86_64
    @6tr6tr:
    As already has been pointed out, the syntax of "rename" is:
    Code:
    rename [options] expression replacement files
    So the correct command line for what you want to achieve would be:
    Code:
    rename -v image img *.png

  9. #9
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    11,470
    Blog Entries
    2

    Default Re: "rename" command is not working

    Quote Originally Posted by wolfi323 View Post
    What he wrote is no pathname, but a sed-style replacement expression.
    He wants to replace the string "image" with "img" in all *.png file names AFAIUI.


    Of course "rename" is no BASH command, just like "mv" is not.
    But both are standard (on openSUSE at least) LINUX commands:
    Code:
    # rpm -qf /usr/bin/rename
    util-linux-2.21.2-10.2.1.x86_64
    # rpm -qf /usr/bin/mv
    coreutils-8.17-6.2.1.x86_64
    @6tr6tr:
    As already has been pointed out, the syntax of "rename" is:
    Code:
    rename [options] expression replacement files
    So the correct command line for what you want to achieve would be:
    Code:
    rename -v image img *.png
    Cool.
    Yes, I just ran some testing to see how it works.
    Lean something new every day.

    TSU

  10. #10

    Default Re: "rename" command is not working

    Quote Originally Posted by ab View Post
    What you probably want, based on your regex (rename doesn't use regexes
    like that I do not think), is the following:

    Code:
    --------------------
    rename 'image' 'img' *.png
    --------------------

    and that will change things like these:

    'image name here.png'
    'some dumb image.png'
    imageur.png

    to theseL

    'img name here.png'
    'some dumb img.png'
    imgur.png

    Good luck.
    Thank you that worked! All the examples I found online had the syntax I used. Must be the synatx for a different "rename" program?

Page 1 of 2 12 LastLast

Posting Permissions

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