BASH Script to Rename Multiple Files

  • Thread starter Thread starter minger
  • Start date Start date
  • Tags Tags
    files Multiple
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 7K views
Science Advisor
Messages
1,494
Reaction score
2
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,
 
Physics news on Phys.org
Try something on the lines of
Code:
for (( i=1 ; i<$N ; i++ )) do
  of=`printf 'flow%04d.fast' $i`
  nf=`printf 'flow%03d.fast' $i`
  mv $of $nf
done
 
Is there any chance you can explain the code a little? I'm not sure I understand it properly