I'm in directory
This will happen if the current directory is a symlink.
cd to a symlink,
.. will refer to the symlink target's parent:
$ ln -s /tmp mylink $ cd mylink $ pwd /home/me/mylink $ realpath . /tmp $ realpath .. /
However, bash will confuse you by being clever and have
cd .. behave differently. Here's
`..' is processed by removing the immediately previous pathname component back to a slash or the beginning of DIR.
This means that when you
cd .., bash will magically take you from
/home/me. This difference is very confusing, but also very useful.
If you use
cd -P .., this magic is not invoked, and it will take you from
/, just like all other tools would.
This is easier when you realize that
.. is not in any way special syntax that means "parent directory". Every directory actually has an honest-to-Linus entry named
On older Unix systems, this was just a convenient convention, and
mkdir /foo/bar would also automatically
ln /foo /foo/bar/.. which you could delete or relink as you wanted. Today, it is instead strictly enforced by the file system.
/tmp/.. links to
/, and that doesn't change just because you followed a symlink to get to