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

12번째 줄: 12번째 줄:
*원본 파일 확인
*원본 파일 확인
<source lang='dos'>
<source lang='dos'>
[root@CentOS5 /]# cat /var/local/src/real.txt  
[root@CentOS ~]# echo hello > /test.txt
This is real file.
[root@CentOS ~]# cat /test.txt
Hello world !
hello
[root@CentOS ~]# ll /test.txt
-rw-r--r-- 1 root root 6 Jun 19 21:44 /test.txt
</source>
</source>


*심볼릭 링크 설정  
*심볼릭 링크 설정 및 확인
<source lang='dos'>
<source lang='dos'>
[root@CentOS5 /]# ln -s /var/local/src/real.txt /test.txt
[root@CentOS ~]# ln -s /test.txt /tmp/link.txt
[root@CentOS5 /]# ll | grep test.txt
[root@CentOS ~]# ll /tmp/link.txt  
lrwxrwxrwx 1 root root   23 Jun 19 15:43 test.txt -> /var/local/src/real.txt
lrwxrwxrwx 1 root root 9 Jun 19 21:45 /tmp/link.txt -> /test.txt</source>
</source>
[root@CentOS ~]# cat /tmp/link.txt  
 
hello
*심볼릭 링크 파일 확인
<source lang='dos'>
[root@CentOS5 /]# cat test.txt  
This is real file.
Hello world !
</source>
</source>



2014년 6월 19일 (목) 21:47 판

Creates a symbolic link
리눅스 심볼릭 링크 설정
리눅스 심볼릭 링크 생성

1 명령어

ln -s 원본파일 링크파일

2 실행 예시

  • 원본 파일 확인
[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/link.txt
[root@CentOS ~]# ll /tmp/link.txt 
lrwxrwxrwx 1 root root 9 Jun 19 21:45 /tmp/link.txt -> /test.txt

[root@CentOS ~]# cat /tmp/link.txt hello </source>

3 하드 링크와 비교

  • 심볼릭 링크 : 원본 파일을 가리키는 방법
  • 하드 링크 : 원본파일과 동일한 위치 헤더를 가진 파일을 생성하는 방법[1]
  • 두 링크 파일 확인 (심볼릭 링크 : test.txt , 하드 링크 : hardlink.txt)
[root@CentOS5 /]# ll | egrep "hardlink|test.txt"
-rw-r--r--  2 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
[root@CentOS5 /]# cat /hardlink.txt 
This is real file.
Hello world !
[root@CentOS5 /]# cat /test.txt 
This is real file.
Hello world !
  • 링크 원본 제거
[root@CentOS5 /]# rm -rf /var/local/src/real.txt
[root@CentOS5 /]# cat /var/local/src/real.txt
cat: /var/local/src/real.txt: No such file or directory
  • 원본 제거 후 두 링크파일 확인
[root@CentOS5 /]# cat /hardlink.txt 
This is real file.
Hello world !
[root@CentOS5 /]# cat /test.txt 
cat: /test.txt: No such file or directory
[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
하드 링크의 경우, 원본과 동일한 헤더위치정보를 가지고 있어 원본 내용확인이 가능하나, 심볼릭링크는 가리키는 존재가 없어져 확인이 불가해짐

4 주석

  1. 파일을 저장할 때 "하드드라이브 특정 위치에 파일 저장 -> 파일 헤더부분에 저장된 위치기록" 여기의 위치정보를 동일하게 하여 다른 이름의 파일을 생성하는 것

5 같이 보기

6 참고 자료

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