I have a directory consists of several files. Files name are as follows;
0102920.05o
0203920.05o
0304920.05o
....
I need to add "0" for all files after the first 4 numbers like;
01020920.05o
02030920.05o
03040920.05o
Is there a way to do it with bash or perl?
Use this command
See if the result is what you want, remove
-n
and-v
options.Explanation:
take this simple command:
Pattern can be regex. So, we can take different part of the text (which is the filename). If you don't understand it, google for regex.
So in the command I suggest, in pattern, it divide the filename into two parts: first part which is first four characters and the second part is the rest.
Now in the result part, we paste first part, add one 0 and then add the second part. As simple as this.
If you can make proper regex, you can easily do bulk rename.
something like that can do the trick in bash for all files in current directory