Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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

2 Answers 2

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
2  
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

Your Answer

 
discard

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.