How to move one directory back in unix / linux when path contains symbolic links?
Asked Answered
C

2

7

I have created a symbolic link to a deeply nested directory. Using symbolic link i can move to that directory from my home directory. I want to move one directory back from the target directory but the shell comes back to the home directory.

[root@pe1800xs ~]# pwd
/root

[root@pe1800xs ~]# mkdir -p abc/def/ghi/jkl/mno/pqr

[root@pe1800xs ~]# ln -s abc/def/ghi/jkl/mno/pqr/ xyz

[root@pe1800xs ~]# cd xyz

[root@pe1800xs xyz]# pwd
/root/xyz

[root@pe1800xs xyz]# pwd -P
/root/abc/def/ghi/jkl/mno/pqr

[root@pe1800xs xyz]# cd ..

[root@pe1800xs ~]# pwd
/root

What I want to achieve is that when I do cd.. in pqr directory the shell should come to mno directory.

Chimaera answered 9/6, 2012 at 12:11 Comment(1)
links in unix act like the files were direct there so naturaly cd.. goes up in the hierarchy like the file were there you can create a link to /root/abc/def/ghi/jkl/mno in the pqr directory and then just cd to itJuly
F
10

You must use

cd -P xyz

to enter into that directory to follow the original structure of folders, then you can move as you wish because you have resolved the link to the real path.

Filature answered 9/6, 2012 at 12:23 Comment(0)
D
7

You have to pass -P option:

cd -P ..
Disney answered 9/6, 2012 at 12:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.