Search code examples
bashawksedfindmv

Howto rename bunch of filenames which are calculated


I want rename bunch of filenames. The rename is based on the calculation of the filename. That means the actual filename + 3600 = new filename. Important is that the underscore in the pid files have to stay.

Thanks in advance!

My system is Debian Stretch.

Actual Filename:

134235.error
134235_.pid
134235.tiff


13893.error
13893_.pid
13893.tiff

1.error
1_.pid
1.tiff

Rename to:

137835.error
137835_.pid
137835.tiff


17493.error
17493_.pid
17493.tiff

3601.error
3601_.pid
3601.tiff

Solution

  • With Perl's standalone rename command. Some distributions call it prename.

    rename -n 's/(\d+)(.+)/${\($1+3600)}$2/' *
    

    If everything looks fine, remove -n.