Going into a directory linked by a link

With POSIX shell, you can use -P option of cd builtin:

cd -P <link>

With bash, from man bash:

The -P option says to use the physical directory structure instead of following symbolic links (see also the -P option to the set builtin command)


Korn-like shells keep track of symbolic links in the path to the current directory (this is known as logical current directory tracking). If you want to expand all symbolic links, pass the option -P to the cd builtin (for physical current directory tracking):

cd -P logic

If you're in a directory which you've accessed via a symbolic link and want to switch the tracked current directory to the path with symbolic links expanded, run

cd -P .

If you want to print the path to the current directory with symbolic links expanded, run pwd -P. In bash, if you want to turn off logical tracking, run set -P; in zsh, run set -w or setopt chase_links.


You can use readlink to determine where your link points, and provide this output as the target of your cd.

cd "$(readlink <link>)"

In the case of additional symlinks pointing to symlinks, readlink will simply provide the target, unless you specify one of it's options to follow symlinks to a canonical file target, for example readlink -f <link>.

readlink - print value of a symbolic link or canonical file name

-f, --canonicalize
canonicalize by following every symlink in every component of the given name recursively; all but the last component must exist

-e, --canonicalize-existing
canonicalize by following every symlink in every component of the given name recursively, all components must exist

-m, --canonicalize-missing
canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence