在AIX系统中,有两种链接文件:软连接和硬链接。他们有些什么却别呢,一下是我的个人理解,如有误之处,请大家指出。
现在系统中创建一个测试目录test,以及在目录下touch一个测试文件test.conf。
然后对test.conf文件创建一个软连接:
1、文件的硬链接是和源文件的权限、大小都是一致的,相当于源文件的别名;软链接只是相当于一个指针指向源文件。
# ln -s test.conf test1.conf
# ls -l
total 0
-rw-r--r-- 1 root system 0 Nov 08 07:52 test.conf
lrwxrwxrwx 1 root system 9 Nov 08 07:52 test1.conf -> test.conf
然后对test.conf文件创建一个硬链接:
# ln test.conf test2.conf
# ls -l
total 0
-rw-r--r-- 2 root system 0 Nov 08 07:52 test.conf
lrwxrwxrwx 1 root system 9 Nov 08 07:52 test1.conf -> test.conf
-rw-r--r-- 2 root system 0 Nov 08 07:52 test2.conf
2、在修改硬链接的两个文件其中一个的权限时,另一个文件权限也一样会被修改;而软连接不会。
# ls -l
total 0
-rw-r--r-- 2 root system 0 Nov 08 08:00 test.conf
-rw-r--r-- 2 root system 0 Nov 08 08:00 test2.conf
# chmod u+x,g+w,o+w test.conf
# ls -l
total 0
-rwxrw-rw- 2 root system 0 Nov 08 08:00 test.conf
-rwxrw-rw- 2 root system 0 Nov 08 08:00 test2.conf
# chmod u-x,g-w,o-w test2.conf
# ls -l
total 0
-rw-r--r-- 2 root system 0 Nov 08 08:00 test.conf
-rw-r--r-- 2 root system 0 Nov 08 08:00 test2.conf
3、软连接可以在任何文件系统下创建,但是硬链接只能在本文件系统中创建。
# ln -s test.conf /test2.conf
# ls -l
total 0
-rw-r--r-- 1 root system 0 Nov 08 07:52 test.conf
lrwxrwxrwx 1 root system 9 Nov 08 07:52 test1.conf -> test.conf
# ln test.conf /test4.conf
ln: test.conf and /test4.conf are located on different file systems.
4、在删除文件时,如果删除源文件之后,软连接不可用,但硬链接任然可以访问源文件中的数据。
#rm test.conf
#more test2.conf
more file
#more test1.conf
test.conf:A file or directory in the path name does not exist.