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.
OK. Here is how I did this. I know it isn't the correct way but in this way there is a chance I'll understand stuff
You can use the printf tool, just make sure your system has it (almost all modern systems have it) To rename them all:
edit: For a random number of files the code would become something like this:
The
ls
provided by GNU coreutils supports version sort:I think ls -v (as noted by @ephemient) does what you want, but if you really have to pad the numbers with zeros, here's a quick and dirty way based on the provided filename pattern