Ubuntu – Show the target of current directory (symbolic link)

cd-commandcommand linesymbolic-link

I'm in directory ~/a which is a symbolic link to ~/b/c. My prompt looks like:

~/a$

But I hope to cd to ~/b/c.

~/a$ cd .
~/a$

It doesn't work. What's the right way?

Best Answer

Here is a way of changing to the target of the given symbolic link:

cd -P .

Here is how it works

user@host:~/tmp$ ls 
@a b
user@host:~/tmp$ file a
a: symbolic link to `b/c'
user@host:~/tmp$ cd a
user@host:~/tmp/a$ cd .
user@host:~/tmp/a$ cd -P .a
user@host:~/tmp/b/c$

You can alias it to

cdl='cd -P'

From the bash manual:

The -P option says to use the physical directory structure instead of following symbolic links