Bash - Adding 0's in the middle of a file name

Posted by user596691 on Stack Overflow See other posts from Stack Overflow or by user596691
Published on 2011-03-09T07:59:29Z Indexed on 2011/03/09 8:10 UTC
Read the original article Hit count: 197

Filed under:
|
|

I have a bunch of files which are named:

mem0.csv
mem1.csv
.
.
.
.
mem153.csv
.
.
.

They are all in the same folder. When I do ls in the folder they appear in an order of

mem0.csv
mem1.csv
mem10.csv
mem100.csv
.
.
.
mem2.csv
mem20.csv
.
.
.

I want to create a bash script to push 0's between mem and the number. I figure that I need to add 0's until all the filenames are of the same length only problem is that I don't know how to do this.

© Stack Overflow or respective owner

Related posts about bash

Related posts about shell