Rename except dot file extension

After reading the manual of the command rename I would like to apply it to a folder with a couple of files containing old style dots before the file-type, e.g. up.to.the.roof.avi. So I'd like to rename them without the dots in between. Therefore I tried it the following way

rename -f -n  's/\.+/./g' *.avi

I assumed already being within the folder -f for file and -n for no acting, just showing what it would be. But nothing happens. So, whats my error? I tried also without the option -f. Nothing. Any hints? Thanks in advance. And py-renamer does not work properly.

How would you like for up.to.the.roof.avi to look after the renaming? If you say "without the dots in between", that would make it as uptotheroofavi . Is that what you meant?

The command rename that you have installed in your system is the Perl script rename or the rename utility from util-linux ? Both have the same name but their behavior is different.

1 Like

learning me, I am using the perl script and whithout the dots in between coud be yes a) jampacked as you set it uptotheroof but without touching the file extension "up to the roof.avi" or b) "up to the roof.avi"

Currently, I do not have any way of testing the Perl rename, however I wonder if the following might work:

rename -n 's/\.(?!\w+$)//g' *.avi

or

rename -n 's/\.(?!avi$)//g' *.avi

Remove the -n once you're satisfied with the result, since that flag means: do a dry run without acting upon it.

This might be another solution in bash. Remove the echo once you know that the dry run works. This will work for any extension, not just avi.

#!/bin/bash

for f in *.*.*; do
    name="${f%.*}"
    ext="${f#${name}}"
    dotless="${name//./}"
    new_name="${dotless}""${ext}"
    if [[ $f != $new_name ]]; then
        echo mv -v "$f" "$new_name"
    fi
done
1 Like

okay, I will try it, and later I can answer if it worked out, because I am now at another machine, trying something quite different, thats why it takes always one or two days for me to try and answer, so many thanks for your efforts, yep, the -n option was taken to not scrum all archive. BTW just 51 movies...
@AIA
BIT LATER, your script did it!!!!!
So now I can try those other two options, that are saving me to do such a task on larger archives, searching and trying, or worse, by hand. THANKS a lot, really.