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


    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


    and I would like to remove one zero from the name so:

    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

    Staff: Mentor

    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
  4. Nov 25, 2008 #3


    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