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.

How can i cd into a symbolically linked directory but, when moving from there, doing it relatively to the real directory?

For example

dir_1
    link_to_dir_3 ->

..

dir_2
    dir_3

If I do cd link_to_dir_3 and then cd .. I wanto tp go to dir_2 and not dir_1. Thanks

share|improve this question

2 Answers 2

cd `pwd -P`
cd ..

(Didn't know that myself and went looking for the answer! The first cd will take you from dir_1/link_to_dir_3 to dir_2/dir_3)

share|improve this answer

Use readlink

cd $(readlink -n link)

share|improve this answer

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.