2014-01-20

하드링크 vs 심볼릭링크 그리고 복사한 파일

1. 원본파일과 복사파일
[root@localhost ~]# touch test.txt
[root@localhost ~]# ls -il 
273833 -rw-r--r--. 1 root root    0 Jan 19 23:26 test.txt

[root@localhost ~]# cp test.txt test2.txt
[root@localhost ~]# ls -il 
273833 -rw-r--r--. 1 root root    0 Jan 19 23:26 test.txt
273834 -rw-r--r--. 1 root root    0 Jan 19 23:26 test2.txt

2. 심볼릭링크와 원본파일
[root@localhost ~]# ln -s test.txt s_test.txt
[root@localhost ~]# ls -li
273835 lrwxrwxrwx. 1 root root    8 Jan 19 23:27 s_test.txt -> test.txt
273833 -rw-r--r--. 1 root root    0 Jan 19 23:26 test.txt
273834 -rw-r--r--. 1 root root    0 Jan 19 23:26 test2.txt

3. 하드링크와 원본파일
[root@localhost ~]# ln test.txt h_test.txt
[root@localhost ~]# ls -il
273833 -rw-r--r--. 2 root root    0 Jan 19 23:26 h_test.txt
273835 lrwxrwxrwx. 1 root root    8 Jan 19 23:27 s_test.txt -> test.txt
273833 -rw-r--r--. 2 root root    0 Jan 19 23:26 test.txt
273834 -rw-r--r--. 1 root root    0 Jan 19 23:26 test2.txt

test.txt ------------> inode(273833) ------> 원본파일데이타
test2.txt ----------> inode(273834) -------> 복사파일데이타
s_test.txt ---------> inode(273835) -------> 원본파일포인트(test2.txt)
h_test.txt ---------> inode(test.txt inode:273833)

하드링크와 심볼릭링크의 차이점
만약 test.txt의 파일을 이동을 하면 심볼릭 링크는 원본파일포인트를 찾을 수가 없어 원본파일데이타를 볼 수 없지만, 하드링크는 test.txt의 파일을 이동하더라도 여전히 test.txt의 inode를 가리키고 있어 원본파일 데이타를 볼 수 있습니다. 참고로 심볼릭링크가 원볼파일포인트를 찾을 수가 없으면 빨간색으로 표기됩니다.
[root@localhost ~]# rm -rf test.txt
[root@localhost ~]# ls -il 
273833 -rw-r--r--. 1 root root    0 Jan 19 23:26 h_test.txt
273835 lrwxrwxrwx. 1 root root    8 Jan 19 23:27 s_test.txt -> test.txt
273834 -rw-r--r--. 1 root root    0 Jan 19 23:26 test2.txt


댓글 없음:

댓글 쓰기