linux class(new) 2 페이지

본문 바로가기
사이트 내 전체검색


회원로그인

linux class(new)

리눅스 file type

페이지 정보

작성자 admin 작성일16-02-06 01:43 조회1,600회 댓글0건

본문

리눅스 파일타입은 ls 명령어로 확인할수 있다.

/root# ls -ld /etc /etc/issue /bin/ls /dev/sda1 /bin/view /usr/include/stdio.h
-rwxr-xr-x. 1 root root 117024 2013-11-23 00:36 /bin/ls ; (-)정규파일
lrwxrwxrwx. 1 root root 2 2014-04-09 03:02 /bin/view -> vi ; (l)심볼릭링크파일
brw-rw----. 1 root disk 8, 1 2016-02-06 00:36 /dev/sda1 ; (b)블럭장치파일
drwxr-xr-x. 155 root root 12288 2016-02-06 00:36 /etc ; (d)디렉토리파일
-rw-r--r--. 1 root root 47 2013-11-27 20:53 /etc/issue ; (-)정규파일
-rw-r--r--. 1 root root 31568 2013-11-22 06:21 /usr/include/stdio.h ; (-)정규파일
/root#

출력결과중 첫번째칼럼이 파일타입.
file type 을 좀 더 자세히 출력하려면 file 명령을 사용하면 된다.

/root# file /etc /etc/issue /bin/ls /dev/sda1 /bin/view /usr/include/stdio.h
/etc: directory
/etc/issue: ASCII text
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
/dev/sda1: block special
/bin/view: symbolic link to `vi'
/usr/include/stdio.h: ASCII C program text
/root#


- : 정규파일 - 디렉토리, 장치파일, 링크파일등 몇가지 종류의 파일타입을 제외한 나머지
모든 파일이 정규파일이다.
- 바이너리 코드값이나 아스키코드값등이 저장되어 있는 파일
- 텍스트 편집기, 이미지 편집기 및 컴파일러등으로 생성할수 있다.

d : 디렉토리파일
파일명과 파일의 inode number 값이 저장되어 있는 파일
(파일내용은 디렉토리에 저장되지 않는다)
디렉토리의 크기는 디렉토릭내의 파일크기와는 무관하다.
mkdir 명령어로 생성한다.

l : 심볼릭링크파일
- 원본파일의 경로가 저장되는 파일.
*. 링크파일의 퍼미션은 항상 rwxrwxrwx 이다.
(링크파일의 실제 퍼미션은 원본파일의 퍼미션을 따른다)

/tmp/test# cp /etc/issue /tmp/testfile
/tmp/test# ls -l /tmp/testfile
-rw-r--r--. 1 root root 47 2016-02-06 01:14 /tmp/testfile
/tmp/test# ln -s /tmp/testfile test.txt ; -s 옵션을 붙이지 않으면 심볼릭링크가 아니다.
/tmp/test# ls -l
합계 0
lrwxrwxrwx. 1 root root 13 2016-02-06 01:14 test.txt -> /tmp/testfile
/tmp/test# echo hello 1> test.txt
/tmp/test# ls -l /tmp/testfile test.txt
-rw-r--r--. 1 root root 6 2016-02-06 01:14 /tmp/testfile
lrwxrwxrwx. 1 root root 13 2016-02-06 01:14 test.txt -> /tmp/testfile
/tmp/test# chmod 600 test.txt
/tmp/test# ls -l /tmp/testfile test.txt
-rw-------. 1 root root 6 2016-02-06 01:14 /tmp/testfile
lrwxrwxrwx. 1 root root 13 2016-02-06 01:14 test.txt -> /tmp/testfile
/tmp/test# rm /tmp/testfile
rm: remove 일반 파일 `/tmp/testfile'? y
/tmp/test# ls -l
합계 0
lrwxrwxrwx. 1 root root 13 2016-02-06 01:14 test.txt -> /tmp/testfile
/tmp/test# cat test.txt
cat: test.txt: 그런 파일이나 디렉터리가 없습니다
/tmp/test#


장치파일은 block 장치파일과 characer 장치파일이 있으며 입출력 단위에 따라 구분된다.
입출력이 블록단위로 이루어지는것은 블록장치파일이며 character 장치파일은 입출력 단위가
byte 단위이다.
그리고 장치파일은 major number 및 minor number 값으로 식별할 수 있다.

b : block 장치파일
brw-r----- 1 root disk 8, 3 10월 23 17:03 /dev/sda3 (8 : major number, 3:minor number)

# ls -l /dev/pts/1
crw--w---- 1 root tty 136, 1 10월 23 18:14 /dev/pts/1
터미널 장치는 문자장치파일이다.
*. 장치파일을 생성하는 명령은 mknod 이다.(옵션은 mknod --help 참조)

하드링크
- 원본과 같은 데이터블럭,같은 inode table 을 사용하는 파일.
그러므로 원본과 링크파일은 구분할 수 없다. 항상 똑같은 내용, 똑같은 속성을
갖는 파일이다.
하드링크는 항상 똑 같은 내용과 속성을 갖고 있어야 하는 파일인 경우에 적합하다.

하드링크 생성방법 : ln 소스파일 링크파일 ; -s 옵션을 사용하면 하드링크가 아니다.

/root# cd /tmp
/tmp# rm -rf test ; mkdir test ; cd test
/tmp/test# echo hello > a.txt
/tmp/test# ln a.txt b.txt
/tmp/test# rm b.txt
rm: remove 일반 파일 `b.txt'? y
/tmp/test# ln -s a.txt b.txt
/tmp/test# ln a.txt a2.txt
/tmp/test# ll
합계 8
-rw-r--r--. 2 root root 6 2016-02-06 00:55 a.txt
-rw-r--r--. 2 root root 6 2016-02-06 00:55 a2.txt
lrwxrwxrwx. 1 root root 5 2016-02-06 00:56 b.txt -> a.txt
/tmp/test# ln a2.txt a3.txt
/tmp/test# ls -l
합계 12
-rw-r--r--. 3 root root 6 2016-02-06 00:55 a.txt
-rw-r--r--. 3 root root 6 2016-02-06 00:55 a2.txt
-rw-r--r--. 3 root root 6 2016-02-06 00:55 a3.txt
lrwxrwxrwx. 1 root root 5 2016-02-06 00:56 b.txt -> a.txt
/tmp/test# ls -i
427948 a.txt 427948 a2.txt 427948 a3.txt 427950 b.txt
/tmp/test# echo test >> a2.txt
/tmp/test# ll
합계 12
-rw-r--r--. 3 root root 11 2016-02-06 00:57 a.txt
-rw-r--r--. 3 root root 11 2016-02-06 00:57 a2.txt
-rw-r--r--. 3 root root 11 2016-02-06 00:57 a3.txt
lrwxrwxrwx. 1 root root 5 2016-02-06 00:56 b.txt -> a.txt
/tmp/test# rm a.txt
rm: remove 일반 파일 `a.txt'? y
/tmp/test# ll
합계 8
-rw-r--r--. 2 root root 11 2016-02-06 00:57 a2.txt
-rw-r--r--. 2 root root 11 2016-02-06 00:57 a3.txt
lrwxrwxrwx. 1 root root 5 2016-02-06 00:56 b.txt -> a.txt
/tmp/test# cat b.txt
cat: b.txt: 그런 파일이나 디렉터리가 없습니다
/tmp/test# cat a2.txt
hello
test
/tmp/test#


*. 하드링크 파일을 삭제하더라도 링크걸린 다른 파일은 같이 삭제 되지는 않으며
하드링크 카운터가 감소한다.
* 하드링크는 같은 파일시스템 내에서만 링크를 걸수 있다.
* 디렉토리에는 직접 하드링크를 걸수는 없지만 디렉토리 속성이 갖는
. 과 .. 때문에 디렉토리를 생성하면 자동으로 하드링크가 걸리게 된다.

댓글목록

등록된 댓글이 없습니다.


접속자집계

오늘
58
어제
75
최대
611
전체
448,108
개인정보취급방침 서비스이용약관 twoseven.kr All rights reserved.
상단으로