Find the answer to your Linux question:
Results 1 to 6 of 6
Hey there suppose i create a symlink to a directory music in /usr/local/goodies/music as Code: ln -s /usr/local/goodies/music music this link has been created in my present dir ok. Now ...
  1. #1
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493

    Going into the parent dir of symlink

    Hey there
    suppose i create a symlink to a directory music in /usr/local/goodies/music as
    Code:
    ln -s /usr/local/goodies/music  music
    this link has been created in my present dir ok. Now when I cd music I see the contents of /usr/local/goodies/music and pwd shows me ../music (which is inside the location where i created the link). Now after getting into usr/local/goodies/music using the link I can't go to goodies using cd.. . Is there a way to go to goodies form the symlink???
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    The Linux file system caches the path, so it will return you to the original directory and not /usr/local/goodies because it expects you to think you are navigating locally. Some Unix systems would not behave this way, and I always found it to be a real pain, because backing out of a link, I would find myself somewhere else!

    However, you can use the -P option to the cd command, which will not follow the symbolic path, but will use the REAL path to the directory. So, if you execute the following command from your directory, you will be in /usr/local/goodies/music, and backing out with cd .. will put you in goodies: cd -P music
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Trusted Penguin Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,392
    You can also use 'cd -' which will take you back to where you were before you used 'cd <dirname>'.
    Linux user #126863 - see http://linuxcounter.net/

  4. #4
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    Quote Originally Posted by Roxoff View Post
    You can also use 'cd -' which will take you back to where you were before you used 'cd <dirname>'.
    The problem that i m facing here is cd -P doesn't take me to the parent dir of the directory to which the link point but take me to the dir where i made the symblink
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,970
    It will take you to the simlink'd directory, but then cd .. will take you up to the parent of that.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Linux User vickey_20's Avatar
    Join Date
    Mar 2009
    Location
    Mumbai, India
    Posts
    493
    ok finally cleared my concepts. If i do
    Code:
     cd -P MUSIC
    without entering the symblink , then I go to the parent dir of the symblink. BUT when you enter inside the symblink and the issue this command
    Code:
    cd - P
    then you go to the parent of the symblink ie the location where the syblink resides. So to go to the actual parent once inside the syblink issue this command
    Code:
    cd -p .
    Hope this explains it.
    Only if I could understand the man pages
    Registered Linux user #492640
    OS: RHEL4,5 ,RH 9,Ubuntu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...