Rename and add a number to all folders in a directory
I have a simulation folder on hpc which contains time directories from 0 to 50 with a step of 0.1 (so 501 folders in total with their names as 0, 0.1, 0.2.. and so forth).
Example output of ls
:
0 0.1 0.2 0.3 0.4 0.5 ..... 49.5 49.6 49.7 49.8 49.9 50
I want to add a specific number, lets say 60 to all the folder names such that the new folder names will be from 60 to 110.
Required output of ls
:
60 60.1 60.2 60.3 60.4 60.5 ..... 109.5 109.6 109.7 109.8 109.9 110
There are several similar questions I found on the site but none that point to a solution to this.
Can anyone please help me out with this problem?!
Thanks!
Edit: The directories are in Ubuntu 22.04.3
Using Perl’s rename
:
$ ls
0.1 0.2 0.3
$ rename -n 's|./(.*)|$1 + 100|e' ./*
rename(0.1, 100.1)
rename(0.2, 100.2)
rename(0.3, 100.3)
Remove -n
switch, aka dry-run when your attempts are satisfactory to rename for real.