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.


Type in:

cd ..

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

  • 2
    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 moving away from SE Jun 6 '12 at 15:34
  • 4
    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
  • The cd -P .. in comments here worked great in macOS out-of-the-box. – Eric Majerus Oct 26 '18 at 19:29
  • Why isn't cd -P .. the answer? cd .. has obviously been tried by anyone who googled this. – Mateen Ulhaq Oct 31 '18 at 1:09

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

cd "$(pwd -P)/.."
  • I didn't know this before. Thanks :) – songyy Jun 6 '12 at 16:38
  • Works great on macOS out-of-the-box, unlike the other answer with just cd .. – Eric Majerus Oct 26 '18 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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