Prevent 'cd' remembering symbolic links traversed

If you type set -P in bash all commands such as cd, pwd will follow the physical path. Else you can use cd -P and pwd -P for temporary changes to the default behavior.

From the manpage of bash:

          -P      If  set,  the shell does not follow symbolic links when executing commands such as cd that change the cur-
                  rent working directory.  It uses the physical directory structure instead.  By default, bash  follows  the
                  logical chain of directories when performing commands which change the current directory.

To make this permanent, put it in your ~/.bashrc file, for example.


"cd" is a built in in most shells. In bash, you can get the behavior you want by adding

set -P

in a startup script (.bashrc, say).


On Ubuntu/Debian (not sure about BSD), cd -P symlink puts me in the resolved symlink path. (Same behavior as pwd -P)

Tested using:

mkdir a
ln -s a b
cd -P b && pwd