BASH Script to Rename Multiple Files

  • Thread starter Thread starter minger
  • Start date Start date
  • Tags Tags
    files Multiple
AI Thread Summary
The discussion centers on creating a bash shell script to rename a series of files by removing a leading zero from their names. The files are named in a sequential format from flow0001.fast to flow0024.fast. The suggested script utilizes a for loop to iterate through the file numbers, using `printf` to format the old and new file names appropriately. The `mv` command is then employed to rename each file. The user seeks clarification on how the code functions, indicating a need for a better understanding of the script's components and logic.
minger
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,
 
Technology 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
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top