Let's say you have directories
/dir2/linked, where the latter is a symlink to the former.
pwd, you get the output
/dir2/linked. If you then
cd .., you'll be put on
/dir2. This behaviour is consistent with the concept of you being in
/dir2/linked before. However, as I understand it, the parent directory (
..) of any directory is stored in the directory inode (i.e.:physically in the disk). Obviously, since
/dir2/linked is really
/dir1, the parent directory on the inode must be
To further complicate matters, while inside
/dir2/linked, the outputs of
ls .. and
cd .. ; ls . are different! It seems like
cd honors the symlinked path, while
ls honors the "physical" path. As mentioned in this question, there's
cd -P for this use case, though.
man pwd mentions "physical" and "logical" working directories, but I still have a few questions at this point:
- Is this behaviour always provided by the
PWDenvironment variable, as mentioned in
- Why do default
lshave different behaviours, if they're both shell commands (i.e.: not programs)?
- Does the typical program (not shell command) use
PWDinstead of the physical path? I realize it's up to the implementation, but is there any rule of thumb?