'링크관련명령어'에 해당되는 글 1건

  1. 2008.08.07 Chapter 5. Unix Basic Commands _ 링크 관련 명령어
2008. 8. 7. 17:47

Chapter 5. Unix Basic Commands _ 링크 관련 명령어

ln CMD

__________

 

make hard or symbolic links to files

 

     The ln utility may be used to create  both  hard  links  and

    symbolic  links.  A  hard link is a pointer to a file and is

    indistinguishable from the  original  directory  entry.  Any

     changes to a file are effective independent of the name used

     to reference the file. Hard links may not span file  systems

     and may not refer to directories.

 

■ 하드 링크(Hard Link)

■ 심볼릭 링크(Symbolic Link, Soft Link)

 

 

(1) 하드 링크(Hard Link)

# ln file1 file2

- file1, file2의 용량은    같은가?

- file1, file2 inode number    같은가?

- file1을 편집하면 file2의 내용은 어떤가?

- "ls -li file*"하면 특이한 변화는 있는가?

- When Original   File Delete!!

- filesystem을 넘어서 링크를 걸수 있는가?

 

 

(2) 십볼릭 링크(Symbolic Link)

# ln -s  file1 file2

- file1, file2의 용량은    같은가?

- file1, file2 inode number    같은가?

- file1을 편집하면 file2의 내용은 어떤가?

- "ls -li file*"하면 특이한 변화는 있는가?

- When Original   File Delete!!

- filesystem을 넘어서 링크를 걸수 있는가?

 

 

(기본 설정 점검)

- 파일에 관련한 하드 링크는 1이다.

- 디렉토리 관련한 하드 링크는 2이다.

 

(실습 준비)

# mkdir /test

# cd /test

# rm -r *

 

(기본 설정 점검 실습)

# touch file1

# ls -l file1

-rw-r--r--   1 root     other          0  2  5 15:42 file1

Hard Link Count : 1

 

# mkdir dir1

# ls -l

drwxr-xr-x   2 root     other        512  1  8 20:47 dir1

Hard Link Count : 2

 

 

[EX] 하드 링크 실습

# echo 111 > file1

# cat file1

 

# ln file1 file2

# ls -l        (파일의 크기 점검, 링크 카운트)

# ls -li      (Inode 번호 점검)

# echo 2222 >> file2

# cat file2

 

# cat file1    (파일의 내용 확인)

 

# rm file1    (원본 파일(Original File)을 지우면!!)

# cat file2

 

 

[EX] 심볼릭 링크 실습

# ln -s file2 file3

# ls -l        (파일의 크기 점검, 링크 카운트 점검)

# ls -li      (Inode 번호 점검)

# echo 3333 >> file3

# cat file2    (파일의 내용 점검)

 

# rm file2    (원본 파일(Original File)을 지우면!!)

# cat file3

 

 

[참고] 일반 파일의 하드 링크 확인 방법(링크 카운트 값을 확인한다.)

file1 file2가 하드링크가 되어 있는지 확인 하는 방법

- ls 명령어의 -i 옵션을 사용하여 Inode 번호를 확인 한다.

         # ls -li file*

- find 명령어의 -inum 옵션을 사용한다.

         # find . -inum 450 -type f



심볼릭 vs 하드 링크

다른 파티션or 슬라이스를 넘어서 링크를 걸 수 있다.

하드링크에서는 모든게 원본 파일이 된다.



출처 : http://cafe.daum.net/bscsolaris