Skip to main content
edited tags
Link
shynur
  • 107
  • 6
edited title
Link
shynur
  • 107
  • 6

Symbolic Link seems to be Contradictory when dealing with `'../`'

added 6 characters in body
Source Link
shynur
  • 107
  • 6
  1. _

    [/tmp/]$ cd sb # `pwd' says we are now in /tmp/ # let's change to /tmp/a/b/ [/tmp/sb/]$ cd ../ # Now we are in /tmp/a/b/ # But what is /tmp/a/b/'s parent dir? [/tmp/]$ # See? We didn't come back to /tmp/a/ BUT /tmp/ 

    It means that the current parent dirparent dir is the second from the right printed by pwd.

  2. Let's add a symlink into dir /tmp/a/b/:

    /tmp/ |__a/ | |__b/ | |__sa=../ -> /tmp/a/ # [/tmp/a/b/]$ ln -s ../ sa | |__sb=./a/b/ -> /tmp/a/b/ 

    This time, we will come back to the actual parent dirparent dir of /tmp/a/b/.:

    [/tmp/]$ cd sb # change to /tmp/a/b/ [/tmp/sb/]$ cd sa # sa=../ # /tmp/sb/=/tmp/a/b/ # ^ or ^ [/tmp/sb/sa/]$ ls --classify b/ # ??? # We are now in /tmp/a/ because there is a b/ here! 

    So Why this time it chooses to refer to the absolute path to determine the parent dirparent dir?

  1. _

    [/tmp/]$ cd sb # `pwd' says we are now in /tmp/ # let's change to /tmp/a/b/ [/tmp/sb/]$ cd ../ # Now we are in /tmp/a/b/ # But what is /tmp/a/b/'s parent dir? [/tmp/]$ # See? We didn't come back to /tmp/a/ BUT /tmp/ 

    It means that the current parent dir is the second from the right printed by pwd.

  2. Let's add a symlink into dir /tmp/a/b/:

    /tmp/ |__a/ | |__b/ | |__sa=../ -> /tmp/a/ # [/tmp/a/b/]$ ln -s ../ sa | |__sb=./a/b/ -> /tmp/a/b/ 

    This time, we will come back to the actual parent dir of /tmp/a/b/.

    [/tmp/]$ cd sb # change to /tmp/a/b/ [/tmp/sb/]$ cd sa # sa=../ # /tmp/sb/=/tmp/a/b/ # ^ or ^ [/tmp/sb/sa/]$ ls --classify b/ # ??? # We are now in /tmp/a/ because there is a b/ here! 

    So Why this time it chooses to refer to the absolute path to determine the parent dir?

  1. _

    [/tmp/]$ cd sb # `pwd' says we are now in /tmp/ # let's change to /tmp/a/b/ [/tmp/sb/]$ cd ../ # Now we are in /tmp/a/b/ # But what is /tmp/a/b/'s parent dir? [/tmp/]$ # See? We didn't come back to /tmp/a/ BUT /tmp/ 

    It means that the current parent dir is the second from the right printed by pwd.

  2. Let's add a symlink into dir /tmp/a/b/:

    /tmp/ |__a/ | |__b/ | |__sa=../ -> /tmp/a/ # [/tmp/a/b/]$ ln -s ../ sa | |__sb=./a/b/ -> /tmp/a/b/ 

    This time, we will come back to the actual parent dir of /tmp/a/b/:

    [/tmp/]$ cd sb # change to /tmp/a/b/ [/tmp/sb/]$ cd sa # sa=../ # /tmp/sb/=/tmp/a/b/ # ^ or ^ [/tmp/sb/sa/]$ ls --classify b/ # ??? # We are now in /tmp/a/ because there is a b/ here! 

    So Why this time it chooses to refer to the absolute path to determine the parent dir?

added 5 characters in body
Source Link
shynur
  • 107
  • 6
Loading
added 5 characters in body
Source Link
shynur
  • 107
  • 6
Loading
added 116 characters in body
Source Link
shynur
  • 107
  • 6
Loading
added 47 characters in body
Source Link
shynur
  • 107
  • 6
Loading
added 95 characters in body
Source Link
shynur
  • 107
  • 6
Loading
added 17 characters in body
Source Link
shynur
  • 107
  • 6
Loading
Source Link
shynur
  • 107
  • 6
Loading