Cent OS로 파일 및 디렉터리 관리

Hard link와 Symbolic link

Hard link

- 특정 파일 또는 디렉터리에 접근을 쉽게 할 수 있도록 하는 방법

- 파일 시스템이 물리적인 장치인 하드디스크 상에 저장되어 있는 특정 파일의 위치를 가리키는 것

 

Symbolic link

- 윈도우의 바로가기 개념

- 디스크 상의 파일을 가리키는 것이 아니라 파일 시스템 상의 특정 파일을 가리키는 것

 

(실습)

[user@localhost 바탕화면]$ su - root

[root@localhost ~ ] # cd /

[root@localhost / ] # mkdir test

[root@localhost / ] # cd test

[root@localhost test] # cat > aaa #aaa파일을 만들고 내용 작성

Hello~!

Ctrl + c 클릭

 

[root@localhost test] # cp aaa aaa_cp #파일복사

[root@localhost test] # ln aaa aaa_hl #하드링크 파일

[root@localhost test] # ln -s aaa aaa_sl #심볼릭링크 파일

[root@localhost test] # ls -l #목록확인

 

 

[root@localhost test] # cat aaa

[root@localhost test] # cat aaa_cp

[root@localhost test] # cat aaa_hl

[root@localhost test] # cat aaa_sl

[root@localhost test] # ls -il

 

ls -il과 ls -l과 차이점은 i-node의 유무입니다. i-node는 저장소에 저장되는 주소를 뜻합니다.
확인해 보면 aaa와 aaa_hl의 i-node가 동일합니다.

 

[root@localhost test] # cat >> aaa

iam user

Ctrl + c 클릭

root@localhost test] # cat aaa

[root@localhost test] # cat aaa_cp

[root@localhost test] # cat aaa_hl

[root@localhost test] # cat aaa_sl

 

> 덮어쓰기
>> 추가하기

 

root@localhost test] # rm -rf aaa #파일삭제

root@localhost test] # cat aaa

[root@localhost test] # cat aaa_cp

[root@localhost test] # cat aaa_hl

[root@localhost test] # cat aaa_sl

 

cp 파일은 aaa파일을 수정 시에 변하지 않았고 aaa파일이 삭제되어도 cp파일은 그대로 남아있습니다.

hl 파일도 aaa파일이 삭제되어도 남아있습니다. 그러나 sl 파일은 함께 삭제되었습니다.

sl 파일은 aaa라는 파일의 주소를 가리키고 있습니다. (원본파일로 가서 원본파일이 가리키고 있는 값을 보여주는 것)
hl파일은 직접적 주소를 가리키고 있어, 실제 파일이 저장되어 있는 주소를 가리킵니다.

 

[root@localhost test] # rm -rf ./* #폴더 안 파일 전체 삭제

[root@localhost test] # cat > bbb

Hello world

Ctrl + c 클릭

[root@localhost test] # ln -s /test/bbb /test/bbb_s

[root@localhost test] # ls -il

 

심볼릭 링크를 만들 때는 반드시 원본파일의 경로명을 지정해 주는 것이 좋습니다.

 

[root@localhost test] # rm -rf ./* #폴더 안 파일 전체 삭제

 

[root@localhost test] # touch aaa

[root@localhost test] # ls -l

[root@localhost test] # touch aaa

[root@localhost test] # ls -l

 

touch는 파일이 아무것도 없을 때는 생성해 주고, 파일이 있을 때는 파일의 생성시간을 바꿔줍니다.(사진에서 시간확인)

 

권한 설정

chmod : 파일 허가권 변경 명령어

ex) chomd 777 aaa

 

chown/chgrp : 파일의 소유권을 바꾸는 명령어

ex)

chown user aaa

chgrp user aaa

 

(실습)

[root@localhost test] # chmod 755 aaa #권한 변경 시 사용

[root@localhost test] # ls -l

[root@localhost test] # chown user aaa #소유자 변경 시 사용

[root@localhost test] # ls -l

[root@localhost test] # chgrp  user aaa #그룹 변경 시 사용

[root@localhost test] # ls -l

 

[root@localhost test] # rm -rf ./*

 

umask

- default 권한 값을 변경

- 새로 생성되는 파일이나 디렉터리의 기본 허가권 값을 지정

- 파일의 기본 권한 666, 디렉토리의 기본 권한 777

 

(실습)

[root@localhost test] # umask #0022

[root@localhost test] # touch aaa

[root@localhost test] # mkdir bbb

[root@localhost test] # ls -l

 

[root@localhost test] # umask 0775

[root@localhost test] # touch ccc

[root@localhost test] # mkdir ddd

[root@localhost test] # ls -l

 

=> 파일 ccc의 권한 002, 디렉토리 ddd의 권한 002

 

ex) mask 0064

000 110 100 => 064
   111 001 011  => 보수
& 110 110 110 => 666
---------------------
   110 000 010  => 602(파일권한)

000 110 100 => 064
   111 001 011  => 보수
& 111 111 111 => 777
---------------------
   111 001 011  => 713(파일권한)

 

특수 권한

Set-UID : Set-UID가 부여된 파일을 실행 시, 파일 소유자 권한으로 인식

Set-GID : Set-GID가 파일에 설정되어 있을 경우 소유한 그룹 권한으로 인식, Set-GID는 주로 디렉터리에 설정(사용자가 속한 그룹에 상관없이 디렉토리 소유 그룹 권한으로 만들어짐)

Sticky-Bit : 공유 디렉터리로 사용

 

Set-UID와 Set-GID

- 프로세스가 실행되는 동안 해당 프로세스의 root 권한을 임시 가져오는 기능

- 프로세스가 사용자보다 높은 수준의 접근을 요구할 때 사용

 

(실습)

[root@localhost test] # rm -rf ./*

[root@localhost test] # touch aaa

[root@localhost test] # touch bbb

[root@localhost test] # touch ccc

[root@localhost test] # ls -l

 

[root@localhost test] # chmod 4666 aaa

[root@localhost test] # chmod 2666 bbb

[root@localhost test] # chmod 1666 ccc

[root@localhost test] # ls -l

 

chmod 4xxx ==> setUID
chmod 2xxx ==> setGID
chmod 1xxx ==> sticky-Bit

 

[root@localhost test] # touch ddd

[root@localhost test] # touch eee

[root@localhost test] # touch fff

[root@localhost test] # ls -l

 

[root@localhost test] # chmod 4777 ddd

[root@localhost test] # chmod 2777 eee

[root@localhost test] # chmod 1777 ffff

[root@localhost test] # ls -l

 

rw- 
rwS => S는 실행권한이 없음을 의미 => rw- (특수권한)
rws => s는 실행권한이 있음을 의미 => rwx

 

rwS rws rwt aaa.txt
aaa의 일반권한은 rw-, rwx, rwx 
특수권한과 실행권한은 공생

 

특수파일 검색

[root@localhost test] # find / -perm -4000

[root@localhost test] # find / -perm 4000

 

-perm -4000 => #그냥 4000으로 시작하는 애를 찾아!

-perm 4000 => --S --- --- #이 권한이 있는 애를 찾아!!

-perm -4000

 

-perm 4000