How to move one directory back to unix / linux when the path contains symbolic links?

I created a symlink to a deeply nested directory. Using a symbolic link, I can go to this directory from my home directory. I want to move a single directory from the destination directory, but the shell returns 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 the pqr directory, the shell should go to the mno directory.

+7
source share
2 answers

You have to use

 cd -P xyz 

to enter this directory, to keep track of the original folder structure, then you can move as you want, because you have allowed the link to the real path.

+10
source

You need to pass the -P option:

 cd -P .. 
+6
source

All Articles