Newbie here... just tried to change a filename that had 2 dots in its name to a single dot using

rename 's/.././' filename

The file has disappeared but I don't think it has been removed as there is still the same amount of space in memory. Where would this file have been sent to?


The file is called .lename now.

(This is assuming the file was called filename before, your "real" file will have a different name I guess. But however the file was called, the first two characters have been substituted with a ..)

This is because a dot in regular expression is a special character meaning match any character. So, .. is any two characters. As rename only replaces the first match unless you added the global modifier (g), the first two characters of your given filename have been replaced.

Note, that the "replacement" in s/regex/replacement/modifiers is not a regular expression, and thus the . on the right side of your expression s/.././ works as you expected.

Now, where is your file:

Files beginning with a . are hidden files. Thus, you won't see them by running ls. Run ls -a to reveal those files.

Rename your file back using mv .lename filename

Next time, escape characters that are special to regular expressions:

rename 's/\.\././' filename

Also, you could use rename -n ... to do a dry-run and check the results before performing the actual renaming. That would have shown you something like this:

rename(filename, .lename)
| improve this answer | |
  • 2
    Also, you may have started an XY-problem with the regexp. You can rename a file by using the mv command. This command does not have problems with filesnames starting with a dot. Adding two dashes even lets problems with filenames beginning with a dash go away: mv -- -oldfilename newfilename (if the file was named -oldfilename before). This looks much simpler than a regexp. – rexkogitans Apr 7 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.