Professional Web Applications Themes

rename all file extensions - Linux / Unix Administration

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?...

  1. #1

    Default 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?


    tony Guest

  2. #2

    Default Re: rename all file extensions

    On 2006-02-01, tony wrote: 

    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 | <http://cfaj.freeshell.org>
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence
    Chris Guest

  3. #3

    Default Re: rename all file extensions

    tony wrote: 

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

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

    Xicheng

    Xicheng Guest

  4. #4

    Default Re: rename all file extensions

    tony wrote: 

    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
    Logan Guest

  5. #5

    Default Re: rename all file extensions

    Xicheng wrote: [/ref]
     

    Who said he had a Linux machine? :-)

    - Logan
    Logan Guest

  6. #6

    Default Re: rename all file extensions

    On 2006-02-02, Logan Shaw wrote: [/ref]

    >
    > Who said he had a Linux machine? :-)[/ref]

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

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

  7. #7

    Default Re: rename all file extensions

    On Thu, 2 Feb 2006 03:11:47 -0500, Chris F.A. Johnson <com> wrote: 
    >> 
    >>
    >> Who said he had a Linux machine? :-)[/ref]
    >
    > And, if he does, it may have the other version of rename.[/ref]

    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.


    Dave Guest

  8. #8

    Default Re: rename all file extensions

    Dave Hinz wrote: 
    > >
    > > And, if he does, it may have the other version of rename.[/ref]
    >
    > 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.[/ref]
    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

    Xicheng Guest

  9. #9

    Default Re: rename all file extensions

    On 2 Feb 2006 07:22:20 -0800, Xicheng <com> wrote: 
     [/ref]
     

    Ah. Well that makes sense then.
     

    Thanks for the info!
    Dave

    Dave Guest

  10. #10

    Default Re: rename all file extensions

    Dave Hinz <net> writes:
     [/ref][/ref]
     [/ref]
     

    URL?

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

  11. #11

    Default Re: rename all file extensions

    Tim Skirvin wrote: [/ref]
    > [/ref]

    >
    > URL?[/ref]
    Am not sure if you want the URL of this script.:

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

    Best,
    Xicheng
     

    Xicheng Guest

  12. #12

    Default Re: rename all file extensions

    "Xicheng" <com> writes:
     
    >> URL?[/ref]
    >Am not sure if you want the URL of this script.:[/ref]
     

    That'd be the one, thanks.

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

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

Similar Threads

  1. Why can't I rename this file?
    By Dan in forum Linux / Unix Administration
    Replies: 2
    Last Post: May 13th, 05:31 PM
  2. Rename a file
    By Chinku Simon in forum PERL Beginners
    Replies: 2
    Last Post: October 24th, 05:03 PM
  3. Copy File and Rename
    By St. Claire in forum AIX
    Replies: 1
    Last Post: September 26th, 09:08 PM
  4. Rename an extrenal file
    By biiin webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 0
    Last Post: July 10th, 07:50 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139