I added a symlink to the current directory with ln -s . aa
. If I execute cd aa
, and after that I executed pwd
, the response is /home/sim/aa
.
But if I execute /bin/pwd
it prints /home/sim
(the current directory hasn't changed).
Where does this difference come from?
Best Answer
In most shells including bash,
pwd
is a shell builtin:If you use
/bin/pwd
, you must use the-L
option to get the same result as builtinpwd
:By default,
/bin/pwd
ignores symlinks and prints the actual directory.From
info pwd
:The built-in
pwd
includes symlink by default, except that-P
option is used, or-o physical
set builtin is enabled.From
man bash
: