How to rename file to .. (dot dot)?

You can't rename a file to . or .. because all directories already contain entries for those two names. (Those entries point to directories, and you can't rename a file to a directory.)

mv detects the case where the destination is an existing directory, and interprets it as a request to move the file into that directory (using its current name).

Backslashes have nothing to do with this, because . is not a shell metacharacter. \. and . are the same to bash.


.. is not special, it is just that it already exists.

On Unix, Dos and MS-Windows every directory has a directory . it links back to itself, and a directory .. it links to its parent directory (or self if root directory).

If .. and . are special it is only because you can not remove them (actually you can, you just remove the directory that contains them).

Therefore you can not name any (other) file . or ...

However you can create files ..., \, , ..  (note there is a space after the .., but you can hardly see it here, or easily in you directory listing) or any other name you like; The only reserved character is / (Warning — advanced details: and null, null is a special character, not used for anything except to mark the end of things and sometimes as a separator). . has no special meaning: not to file names, kernel or to the shell, it does not need escaping. Actually if a file-name starts with a . then it is special, the file is normally hidden, but still it does not need escaping.

Aside

This hidden file behaviour came about in an early implementation of ls where the author wanted to hide . and .., so they wrote code to hide any files starting with a .. Other users noticed this bug/feature and started creating files starting with a . when they wanted the file to be hidden.

Explanation of Linked question

In the question you link to the questioner is trying to move the file to the parent directory .. but ends up renaming to ..., files starting with a dot are by default hidden, that is why they can not find it.

When using mv in the form mv a b

  • If you move to . it is effectively a no operation, but mv treats it as an error.
  • If you move to .. it will move the file to the parent directory.

The problem is you're moving a file onto a directory. This is allowed to fail.

I'm going to tell you how it once was.

mkdir used to essentially read this (while I'm writing this in sh, it was really written in C and setuid-root).

mknod d $1
ln -d $1 $1/.
ln -d `dirname $1` $1/..

So as you can see there's not much special about . and .. except for the fact they are created for you by mkdir and already exist. There's code now that says you cannot remove them, but it wasn't always the case.

rmdir used to look like this:

rm -d $1/..
rm -d $1/.
rm -d $1