Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have my code mounted as an sshfs in my home directory, but the hierarchy is difficult to remember, so I created a symlink in my home directory leading to that directory. Is there a way so that when I cd to that symbolic link, instead of cding to the symbolic link, it will actually cd to that directory?

If the question was unclear, here is an example of what I am looking for:

foo@foo:~$ ls -l
lrwxrwxrwx  1 foo      foo              5 2012-11-14 08:20 foo -> bar/bar

foo@foo:~$ cd foo
share|improve this question
two related questions – jw013 Nov 14 '12 at 16:32
up vote 47 down vote accepted

With any POSIX implementation of cd, you can use the -P option to do this.

$ help cd
    -P      use the physical directory structure without following symbolic links

You can see it in action here:

$ mkdir foo
$ ln -s foo bar
$ cd -P bar
$ pwd

If you want this to be the default behaviour, you can either create an alias for cd, like so:

alias cd='cd -P'

...or use set -o physical.

share|improve this answer
Thanks! This is a perfect solution. – bladezzz Dec 3 '12 at 0:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.