LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 775|回复: 1

关于bash、cd和符号链接的问题

[复制链接]
发表于 2006-1-14 13:42:13 | 显示全部楼层 |阅读模式
这样:

  1. $ cd /tmp
  2. $ mkdir -p foo/bar/kid
  3. $ cd foo
  4. # 绝对路径的符号链接
  5. $ ln -s /tmp/foo/bar/kid askid
  6. # 相对路径的符号链接
  7. $ ln -s foo/bar/kid skid
复制代码

之后进入askid:

  1. $ cd askid
  2. $ cd ..
  3. $ pwd
  4. /tmp/foo
复制代码

对于skid也是一样:

  1. $ cd skid
  2. $ cd ..
  3. $pwd
  4. /tmp/foo
复制代码

为什么不是像直接进入kid一样呢:

  1. $ cd bar/kid
  2. $ cd ..
  3. $ pwd
  4. /tmp/foo/bar
复制代码

我的理解,skid和askid都只是符号链接,应该这操作系统的层面的话,skid和askid的父目录都应该是bar才对呀,可是我直接:

  1. $ cd skid/..
  2. $ pwd
  3. /tmp/foo
复制代码

难道bash对这个进行了跟踪?他是如何进行的呢?如果这样的话,如果有很多重符号链接的嵌套的话,是不是要用掉很多资源呀?(不过这确实是一项不错的功能)
发表于 2006-1-16 09:47:18 | 显示全部楼层
Post by pluskid
这样:

  1. $ cd /tmp
  2. $ mkdir -p foo/bar/kid
  3. $ cd foo
  4. # 绝对路径的符号链接
  5. $ ln -s /tmp/foo/bar/kid askid
  6. # 相对路径的符号链接
  7. $ ln -s foo/bar/kid skid
复制代码

之后进入askid:

  1. $ cd askid
  2. $ cd ..
  3. $ pwd
  4. /tmp/foo
复制代码

对于skid也是一样:

  1. $ cd skid
  2. $ cd ..
  3. $pwd
  4. /tmp/foo
复制代码

为什么不是像直接进入kid一样呢:

  1. $ cd bar/kid
  2. $ cd ..
  3. $ pwd
  4. /tmp/foo/bar
复制代码

我的理解,skid和askid都只是符号链接,应该这操作系统的层面的话,skid和askid的父目录都应该是bar才对呀,可是我直接:

  1. $ cd skid/..
  2. $ pwd
  3. /tmp/foo
复制代码

难道bash对这个进行了跟踪?他是如何进行的呢?如果这样的话,如果有很多重符号链接的嵌套的话,是不是要用掉很多资源呀?(不过这确实是一项不错的功能)

A sym link is a pointer to a symbolic path (not the physical data location), which will tell kernel where the target is located. That's why they have different inode refernce number.
  1. ls -ladi dir_name
复制代码
will show the inode number. Because of this feature, they have their own reference context. The filesystem structure of a symlink wouldn't mess up with the target structure. This is all done under the kernel space, nothing to do with the shell.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表