Apparently you can rename file to
If I were insane, how would I rename file to
.? Is such a filename even allowed?
Backslash doesn't seem to disable dot's special meaning:
$ mv test \. mv: `test' and `./test' are the same file
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
.. 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).
. 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
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.
This hidden file behaviour came about in an early implementation of
ls where the author wanted to hide
.., 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.
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
.it is effectively a no operation, but
mvtreats it as an error.
..it will move the file to the parent directory.
You can't rename a file to
.. 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.
. are the same to
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