rename all file extensions - Unix

This is a discussion on rename all file extensions - Unix ; I got hundreds of files in a directory I want to rename from *.cfg.rpmsave to *.cfg What is the fastest way to do this?...

+ Reply to Thread
Results 1 to 12 of 12

Thread: rename all file extensions

  1. rename all file extensions

    I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    to *.cfg


    What is the fastest way to do this?



  2. Re: rename all file extensions

    On 2006-02-01, tony wrote:
    > I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    > to *.cfg
    >
    >
    > What is the fastest way to do this?


    If you have a rename command, use it. On some systems the command
    would be:

    rename .cfg.rpmsave .cfg *.cfg.rpmsave

    There is another version of rename which uses a different syntax.

    If you do not have rename, use this script:

    for file in *.cfg.rpmsave
    do
    nf=${file%.rpmsave}
    mv "$file" "$nf"
    done

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  3. Re: rename all file extensions

    tony wrote:
    > I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    > to *.cfg
    >
    >
    > What is the fastest way to do this?


    if you have 'rename' command in your linux-box, then:

    rename 's#\.rpmsave$##' *.cfg.rpmsave

    Xicheng


  4. Re: rename all file extensions

    tony wrote:
    > I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    > to *.cfg
    >
    >
    > What is the fastest way to do this?


    Like this, if you are using a Bourne-family shell:

    for i in *.cfg.rpmsave
    do
    j=`basename "$i" .rpmsave`
    echo "renaming '$i' to '$j'"
    mv "$i" "$j"
    done

    Hope that helps.

    - Logan

  5. Re: rename all file extensions

    Xicheng wrote:
    > tony wrote:
    >> I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    >> to *.cfg


    > if you have 'rename' command in your linux-box, then:
    >
    > rename 's#\.rpmsave$##' *.cfg.rpmsave


    Who said he had a Linux machine? :-)

    - Logan

  6. Re: rename all file extensions

    On 2006-02-02, Logan Shaw wrote:
    > Xicheng wrote:
    >> tony wrote:
    >>> I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    >>> to *.cfg

    >
    >> if you have 'rename' command in your linux-box, then:
    >>
    >> rename 's#\.rpmsave$##' *.cfg.rpmsave

    >
    > Who said he had a Linux machine? :-)


    And, if he does, it may have the other version of rename.

    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  7. Re: rename all file extensions

    On Thu, 2 Feb 2006 03:11:47 -0500, Chris F.A. Johnson wrote:
    > On 2006-02-02, Logan Shaw wrote:
    >> Xicheng wrote:
    >>> tony wrote:
    >>>> I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    >>>> to *.cfg

    >>
    >>> if you have 'rename' command in your linux-box, then:
    >>>
    >>> rename 's#\.rpmsave$##' *.cfg.rpmsave

    >>
    >> Who said he had a Linux machine? :-)

    >
    > And, if he does, it may have the other version of rename.


    And if he has a compiler, he can install whichever version of rename he
    wants. So, which one works that way? I'd like to stick it on a few
    hundred sun boxes.



  8. Re: rename all file extensions

    Dave Hinz wrote:
    > On Thu, 2 Feb 2006 03:11:47 -0500, Chris F.A. Johnson wrote:
    > > On 2006-02-02, Logan Shaw wrote:
    > >> Xicheng wrote:
    > >>> tony wrote:
    > >>>> I got hundreds of files in a directory I want to rename from *.cfg.rpmsave
    > >>>> to *.cfg
    > >>
    > >>> if you have 'rename' command in your linux-box, then:
    > >>>
    > >>> rename 's#\.rpmsave$##' *.cfg.rpmsave
    > >>
    > >> Who said he had a Linux machine? :-)

    > >
    > > And, if he does, it may have the other version of rename.

    >
    > And if he has a compiler, he can install whichever version of rename he
    > wants. So, which one works that way? I'd like to stick it on a few
    > hundred sun boxes.

    the 'rename' I mentioned is a perl script by Larry Wall. If you have
    Perl 5 and up installed in your system, and are comfortable with some
    simple regex, then you may save a lot of time by using this samll handy
    gadget.. you can copy it directly from other Linux boxes and make it
    executable. make sure you have *perl* in your sun boxes...
    Best,
    Xicheng


  9. Re: rename all file extensions

    On 2 Feb 2006 07:22:20 -0800, Xicheng wrote:
    > Dave Hinz wrote:


    >> And if he has a compiler, he can install whichever version of rename he
    >> wants. So, which one works that way? I'd like to stick it on a few
    >> hundred sun boxes.


    > the 'rename' I mentioned is a perl script by Larry Wall.


    Ah. Well that makes sense then.

    > If you have
    > Perl 5 and up installed in your system, and are comfortable with some
    > simple regex, then you may save a lot of time by using this samll handy
    > gadget.. you can copy it directly from other Linux boxes and make it
    > executable. make sure you have *perl* in your sun boxes...


    Thanks for the info!
    Dave


  10. Re: rename all file extensions

    Dave Hinz writes:

    >>> And if he has a compiler, he can install whichever version of rename he
    >>> wants. So, which one works that way? I'd like to stick it on a few
    >>> hundred sun boxes.


    >> the 'rename' I mentioned is a perl script by Larry Wall.


    >Ah. Well that makes sense then.


    URL?

    - Tim Skirvin (tskirvin@ks.uiuc.edu)
    --
    Theoretical and Computational http://www.ks.uiuc.edu/~tskirvin/
    Biophysics, Beckman Institute, UIUC Senior Systems Administrator

  11. Re: rename all file extensions

    Tim Skirvin wrote:
    > Dave Hinz writes:
    >
    > >>> And if he has a compiler, he can install whichever version of rename he
    > >>> wants. So, which one works that way? I'd like to stick it on a few
    > >>> hundred sun boxes.

    >
    > >> the 'rename' I mentioned is a perl script by Larry Wall.

    >
    > >Ah. Well that makes sense then.

    >
    > URL?

    Am not sure if you want the URL of this script.:

    http://www-verimag.imag.fr/~moy/vrac/rename

    Best,
    Xicheng

    >
    > - Tim Skirvin (tskirvin@ks.uiuc.edu)
    > --
    > Theoretical and Computational http://www.ks.uiuc.edu/~tskirvin/
    > Biophysics, Beckman Institute, UIUC Senior Systems Administrator



  12. Re: rename all file extensions

    "Xicheng" writes:

    >> >> the 'rename' I mentioned is a perl script by Larry Wall.
    >> >Ah. Well that makes sense then.

    >> URL?

    >Am not sure if you want the URL of this script.:


    > http://www-verimag.imag.fr/~moy/vrac/rename


    That'd be the one, thanks.

    (Spending time searching the web for 'rename' wasn't getting very
    far.)

    - Tim Skirvin (tskirvin@ks.uiuc.edu)
    --
    Theoretical and Computational http://www.ks.uiuc.edu/~tskirvin/
    Biophysics, Beckman Institute, UIUC Senior Systems Administrator

+ Reply to Thread