Say I do the following:
cd /some/path
ln -s /target/path symbolic_name
If then do:
cd /some/path
cd symbolic_name
pwd
I get:
/some/path/symblic_name
and not:
/target/path
Is there a way to have the shell "fully resolve" a symbolic link (i.e. updating CWD, etc.), as if I had directly done:
cd /target/path
?
I need to run some programs that seem to be "aware" or "sensitive" about how I get to my target path, and I would like them to think that I arrived to the target path as if had done cd /target/path
directly.
Best Answer
Your shell has a builtin
pwd
, which tries to be "smart". After you did acd
to a symlink the internalpwd
fakes the output as if you moved to a real directory.Pass the
-P
option topwd
, i.e. runpwd -P
. The-P
option (for “physical”) tellspwd
not to do any symbolic link tracking and display the “real” path to the directory.Alternatively, there should also be a real binary
pwd
, which does not do (and is even not able to do) this kind of magic. Just use that binary explicity: