리눅스 심볼릭링크 생성 실습

Jmnote (토론 | 기여)님의 2014년 6월 19일 (목) 22:22 판
Creates a symbolic link
리눅스 심볼릭 링크 설정
리눅스 심볼릭 링크 생성 실습

1 명령어

ln -s 원본파일 링크파일

2 실습

/test.txt 파일을 만들고 그에 대한 심볼릭 링크 파일 /tmp/s_link.txt를 만들어보자.

  • 원본 파일 확인
[root@CentOS ~]# echo hello > /test.txt
[root@CentOS ~]# cat /test.txt
hello
[root@CentOS ~]# ll /test.txt
-rw-r--r-- 1 root root 6 Jun 19 21:44 /test.txt
  • 심볼릭 링크 설정 및 확인
[root@CentOS ~]# ln -s /test.txt /tmp/s_link.txt
[root@CentOS ~]# ll /tmp/s_link.txt 
lrwxrwxrwx 1 root root 9 Jun 19 21:45 /tmp/s_link.txt -> /test.txt
[root@CentOS ~]# cat /tmp/s_link.txt 
hello

3 하드 링크와 차이

[root@CentOS ~]# ln /test.txt /tmp/h_link.txt
[root@CentOS ~]# ls -i /test.txt
98116 /test.txt
[root@CentOS ~]# ls -i /tmp/h_link.txt
98116 /tmp/h_link.txt
[root@CentOS ~]# ls -i /tmp/s_link.txt 
1962252 /tmp/s_link.txt
→ 하드 링크 파일의 inode number는 원본과 같다.
→ 디스크 상에서 근본적으로 같은 파일이라 할 수 있다.[1]
→ 반면 심볼릭 링크는 디스크 상에서 다른 파일이며 그야말로 바로가기 파일일뿐이다.

4 원본 삭제 실습

[root@CentOS ~]# rm -f /test.txt
[root@CentOS ~]# ll /tmp/s_link.txt
lrwxrwxrwx 1 root root 9 Jun 19 22:11 /tmp/s_link.txt -> /test.txt
[root@CentOS ~]# cat /tmp/s_link.txt
cat: /tmp/s_link.txt: No such file or director
→ /tmp/s_link.txt 은 존재하지만 원본인 /test.txt 파일이 없어서 내용은 볼 수 없다.

5 같이 보기

6 주석

  1. 하드 링크가 된 시점에서는 원본과 사본(?)의 구분도 애매하다. 애초에 원본이라는 것도 그 디스크 상의 실제 파일을 가리키는 하드 링크이기 때문이다. 기존의 하드링크 1개(원본)이 있었고 추가로 1개(사본)를 더 생성하여 2개가 되었다는 뜻이다.

7 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}