Sunday, May 5, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1168  / 1 Year ago, sat, april 15, 2023, 9:35:45

I'm in directory ~/a which is a symbolic link to ~/b/c. My prompt looks like:



~/a$


But I hope to cd to ~/b/c.



~/a$ cd .
~/a$


It doesn't work. What's the right way?


More From » command-line

 Answers
7

Here is a way of changing to the target of the given symbolic link:



cd -P .


Here is how it works



user@host:~/tmp$ ls 
@a b
user@host:~/tmp$ file a
a: symbolic link to `b/c'
user@host:~/tmp$ cd a
user@host:~/tmp/a$ cd .
user@host:~/tmp/a$ cd -P .a
user@host:~/tmp/b/c$


You can alias it to



cdl='cd -P'


From the bash manual:




The -P option says to use the physical directory structure instead of following symbolic links



[#35481] Saturday, April 15, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ouschee

Total Points: 485
Total Questions: 88
Total Answers: 106

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
;