Super User is a question and answer site for computer enthusiasts and power users. 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

Say I got a folder with absolute location: /tmp/abc/def, and I created a symbolic link to this folder def, in my home directory. The symbolic link is also called def. Then after I get to the def from my home directory by calling:

cd ~/def

I then want to go to the folder "abc". What should I do then?

I've search for around 20 minutes but didn't find the answer. Thanks.

share|improve this question

migrated from Jun 7 '12 at 10:09

This question came from our site for professional and enthusiast programmers.

I guess you can not do the obvious cd /tmp/abc? – Nobody Jun 6 '12 at 15:31
up vote 1 down vote accepted

Type in:

cd ..

That should bring you to the parent directory of whatever your current directory is.

share|improve this answer
This solution has exactly the problem the OP wants to solve. When entering the directory via symlink, the cd .. will return to the directory that contains the symlink. – Nobody Jun 6 '12 at 15:34
This solution works, but only in certain settings. For example, in bash set -P will enable this, but set +P will cause it to fail. In either case, cd -P .. should work. – William Pursell Jun 6 '12 at 16:18
@WilliamPursell: thanks, this method is clean and cool :) – songyy Jun 6 '12 at 16:37

You can use pwd -P to get the "real" path, so something like this would work:

cd "$(pwd -P)/.."
share|improve this answer
I didn't know this before. Thanks :) – songyy Jun 6 '12 at 16:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .