Bulk renaming files in Linux, OpenSUSE versus (K)Ubuntu (Debian)

 

Switching from OpenSuse to (K)Ubuntu forced me to browse through many of my bash scripts I wrote in the last few years.

One of the strange differences between these two varieties of Linux is the following: to change file names normally the rename command is used as follows:

 

rename .tgz .old *.tgz

 

What would I like to happen when entering this command line in either a bash or a bash script? Well the above mentioned command will simply rename any file that ends with the extension tgz (*.tgz) from .tgz to .old

I used this simple line of text to rename archives from an older backups before overwriting them with new ones. Just to make sure that the old backups don't get lost and stay available for restores. In OpenSUSE this always worked fine but (K)Ubuntu seems to have a problem. This simple line of script code doesn't work but just prompts the following error message:   syntax error at (eval 1) line 1, near "."

In Ubuntu, the rename command is a perl script called 'prename' which seems to have a problem with the above, old, syntax as used under OpenSUSE because the string contains a space between .tgz and .old. After a lot of 'googling' I found that the new, and for this version of Linux working, syntax should be:

 

rename ’s/\.tgz/\.old/’ *.tgz

 

Now my backup scripts are working again, at least in (K)Ubuntu, and as far as my OpenSUSE systems are concerned I stick to my old working scripts!