Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

BASH Script to Rename Multiple Files

  1. Nov 24, 2008 #1

    minger

    User Avatar
    Science Advisor

    Hi guys, this should be a pretty easy thing to do, I'm just not familiar enough with bash shell scripting to do it.

    I have a bunch of files named

    flow0001.fast
    flow0002.fast
    ....
    flow0024.fast

    and I would like to remove one zero from the name so:
    flow001.fast
    flow002.fast
    ...
    flow024.fast

    I could do it by hand, but I may have to do it a few times, so a script would be nice. I know the number of files at all times, so I don't need IFs or any searches for the number of files to change.

    thanks a lot,
     
  2. jcsd
  3. Nov 24, 2008 #2

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    Try something on the lines of
    Code (Text):
    for (( i=1 ; i<$N ; i++ )) do
      of=`printf 'flow%04d.fast' $i`
      nf=`printf 'flow%03d.fast' $i`
      mv $of $nf
    done
     
  4. Nov 25, 2008 #3

    minger

    User Avatar
    Science Advisor

    Is there any chance you can explain the code a little? I'm not sure I understand it properly
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: BASH Script to Rename Multiple Files
Loading...