Shell – How to tell if I’m actually in a symlink location from command line

cd-commandshellsymlinkworking directory

Suppose I have a folder:

cd /home/cpm135/public_html

and make a symbolic link

ln -s /var/lib/class .

Later, I'm in that directory:

cd /home/cpm135/public_html/class

The pwd is going to tell me I'm in /home/cpm135/public_html/class

Is there any way to know that I'm "really" in /var/lib/class ? Thanks

Best Answer

Depending on how your pwd command is configured, it may default to showing the logical working directory (output by pwd -L) which would show the symlink location, or the physical working directory (output by pwd -P) which ignores the symlink and shows the "real" directory.

For complete information you can do

file "$(pwd -L)"

Inside a symlink, this will return

/path/of/symlink: symbolic link to /path/of/real/directory
Related Question