"리눅스 심볼릭링크 생성 실습"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(사용자 2명의 중간 판 22개는 보이지 않습니다)
1번째 줄: 1번째 줄:
{{테스트|CentOS 5.5}}
{{테스트|CentOS 5 및 6}}
;Creates a symbolic link
;Creates a symbolic link
;리눅스 심볼릭 링크 설정
;리눅스 심볼릭 링크 설정
;리눅스 심볼릭 링크 생성
;리눅스 심볼릭 링크 생성 실습


==명령어==
==명령어==
<source lang='bash'>
<syntaxhighlight lang='bash'>
ln -s 원본파일 링크파일
ln -s 원본 링크파일
</source>
</syntaxhighlight>
:→ 원본은 파일, 디렉토리 모두 가능


==실습==
==실습==
/test.txt 파일을 만들고 그에 대한 심볼릭 링크 파일 /tmp/s_link.txt를 만들어보자.
/test.txt 파일을 만들고 그에 대한 심볼릭 링크 파일 /tmp/s_link.txt를 만들어보자.
*원본 파일 확인
*원본 파일 확인
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@CentOS ~]# echo hello > /test.txt
[root@CentOS ~]# echo hello > /test.txt
[root@CentOS ~]# cat /test.txt
[root@CentOS ~]# cat /test.txt
18번째 줄: 19번째 줄:
[root@CentOS ~]# ll /test.txt
[root@CentOS ~]# ll /test.txt
-rw-r--r-- 1 root root 6 Jun 19 21:44 /test.txt
-rw-r--r-- 1 root root 6 Jun 19 21:44 /test.txt
</source>
</syntaxhighlight>


*심볼릭 링크 설정 및 확인
*심볼릭 링크 설정 및 확인
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@CentOS ~]# ln -s /test.txt /tmp/s_link.txt
[root@CentOS ~]# ln -s /test.txt /tmp/s_link.txt
[root@CentOS ~]# ll /tmp/s_link.txt  
[root@CentOS ~]# ll /tmp/s_link.txt  
27번째 줄: 28번째 줄:
[root@CentOS ~]# cat /tmp/s_link.txt  
[root@CentOS ~]# cat /tmp/s_link.txt  
hello
hello
</source>
</syntaxhighlight>


==하드 링크와 비교==
==하드 링크와 차이==
*심볼릭 링크 : 원본 파일을 가리키는 방법
<syntaxhighlight lang='console'>
*하드 링크 : 원본파일과 동일한 위치 헤더를 가진 파일을 생성하는 방법<ref>파일을 저장할 때 "하드드라이브 특정 위치에 파일 저장 -> 파일 헤더부분에 저장된 위치기록" 여기의 위치정보를 동일하게 하여 다른 이름의 파일을 생성하는 것</ref>
[root@CentOS ~]# ln /test.txt /tmp/h_link.txt
*두 링크 파일 확인 (심볼릭 링크 : test.txt  ,  하드 링크 : hardlink.txt)
[root@CentOS ~]# ls -i /test.txt
<source lang='dos'>
98116 /test.txt
[root@CentOS5 /]# ll | egrep "hardlink|test.txt"
[root@CentOS ~]# ls -i /tmp/h_link.txt
-rw-r--r--  2 root root    34 Jun 19 15:30 hardlink.txt
98116 /tmp/h_link.txt
lrwxrwxrwx  1 root root    23 Jun 19 15:43 test.txt -> /var/local/src/real.txt
[root@CentOS ~]# ls -i /tmp/s_link.txt  
[root@CentOS5 /]# cat /hardlink.txt  
1962252 /tmp/s_link.txt
This is real file.
</syntaxhighlight>
Hello world !
:→ 하드 링크 파일의 inode number는 원본과 같다.
[root@CentOS5 /]# cat /test.txt  
:→ 디스크 상에서 근본적으로 같은 파일이라 할 수 있다.<ref>하드 링크가 된 시점에서는 원본과 사본(?)의 구분도 애매하다. 애초에 원본이라는 것도 그 디스크 상의 실제 파일을 가리키는 하드 링크이기 때문이다. 기존의 하드링크 1개(원본)이 있었고 추가로 1개(사본)를 더 생성하여 2개가 되었다는 뜻이다.</ref>
This is real file.
:→ 반면 심볼릭 링크는 디스크 상에서 다른 파일이며 그야말로 바로가기 파일일뿐이다.
Hello world !
</source>


*링크 원본 제거
==원본 삭제 실습==
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@CentOS5 /]# rm -rf /var/local/src/real.txt
[root@CentOS ~]# rm -f /test.txt
[root@CentOS5 /]# cat /var/local/src/real.txt
[root@CentOS ~]# ll /tmp/s_link.txt
cat: /var/local/src/real.txt: No such file or directory
lrwxrwxrwx 1 root root 9 Jun 19 22:11 /tmp/s_link.txt -> /test.txt
</source>
[root@CentOS ~]# cat /tmp/s_link.txt
cat: /tmp/s_link.txt: No such file or director
</syntaxhighlight>
:→ /tmp/s_link.txt 은 존재하지만 원본인 /test.txt 파일이 없어서 내용은 볼 수 없다.


*원본 제거 후 두 링크파일 확인
==같이 보기==
<source lang='dos'>
*[[리눅스 심볼릭링크 폴더 생성 실습]]
[root@CentOS5 /]# cat /hardlink.txt
*[[리눅스 하드링크 생성 실습]]
This is real file.
*[[리눅스 심볼릭 링크 확인]]
Hello world !
*[[리눅스 심볼릭 링크]]
[root@CentOS5 /]# cat /test.txt
*[[윈도우 심볼릭 링크 생성]]
cat: /test.txt: No such file or directory
*[[리눅스 ln]]
[root@CentOS5 /]# ll | egrep "hardlink|test.txt"
-rw-r--r--  1 root root    34 Jun 19 15:30 hardlink.txt
lrwxrwxrwx  1 root root    23 Jun 19 15:43 test.txt -> /var/local/src/real.txt
</source>
;하드 링크의 경우, 원본과 동일한 헤더위치정보를 가지고 있어 원본 내용확인이 가능하나, 심볼릭링크는 가리키는 존재가 없어져 확인이 불가해짐


==주석==
==주석==
<references/>
<references/>


==같이 보기==
==참고==
*[[리눅스 심볼릭 링크 확인]]
*[[리눅스 심볼릭 링크]]
*[[윈도우 심볼릭 링크 사용]]
*[[리눅스 하드 링크 설정]]
 
==참고 자료==
*http://en.wikipedia.org/wiki/Symbolic_link
*http://en.wikipedia.org/wiki/Symbolic_link


[[분류: 리눅스]]
[[분류: 리눅스]]
[[분류:심볼릭 링크]]

2020년 11월 2일 (월) 00:56 기준 최신판

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 }}