关于你的第二个问题,如果你使用相对路径创建符号链接,然后移动整个目录结构,它仍然应该工作。考虑以下终端会话:
~$ mkdir test
~$ cd test/
~/test$ mkdir test2
~/test$ cd test2/
~/test/test2$ touch testfile; echo "hello, world" > testfile
~/test/test2$ cat testfile
hello, world
~/test/test2$ cd ..
~/test$ ln -s ./test2/testfile testfileln
~/test$ ls -l
total 8
drwxr-xr-x 2 xxxx xxxx 4096 2010-09-09 09:18 test2
lrwxrwxrwx 1 xxxx xxxx 16 2010-09-09 09:18 testfileln -> ./test2/testfile
~/test$ cd ..
~$ mv test/ testfoo
~$ cd testfoo/
~/testfoo$ ls -l
total 8
drwxr-xr-x 2 xxxx xxxx 4096 2010-09-09 09:18 test2
lrwxrwxrwx 1 xxxx xxxx 16 2010-09-09 09:18 testfileln -> ./test2/testfile
/testfoo$ cat testfileln
hello, world
Run Code Online (Sandbox Code Playgroud)
至于你的第一个问题,如果你真的想要一个链接,无论你对文件的原始位置做什么,都会引用同一个文件,那么硬链接可能就是你想要的。硬链接基本上只是引用同一个 inode 的另一个名称。因此,硬链接和“原始文件”之间没有区别。但是,如果您需要跨文件系统进行链接,则硬链接通常不起作用,并且您通常无法对目录进行硬链接。此外,在执行某些文件操作时,您会注意到一些差异。最值得注意的是,删除原始文件不会删除文件。硬链接仍将指向该文件并可访问。
归档时间: |
|
查看次数: |
2305 次 |
最近记录: |