Peter Ahn
Peter의 우아한 프로그래밍
Peter Ahn
전체 방문자
오늘
어제
  • 전체 (115)
    • 영어공부 (15)
    • 물생활 (9)
    • 독서 (2)
    • 일상 (1)
    • IT 소식 (15)
      • 최신 기술 소식 (10)
      • 보안 소식 (5)
    • 인공지능 (AI) (2)
    • OS (19)
      • Linux (19)
    • Web (0)
      • Vue.js (0)
    • 객체지향 (1)
      • 개념과 원리 (1)
      • 디자인패턴 (0)
    • 프로그래밍 (37)
      • C (14)
      • C++ (3)
      • C# (1)
      • Python (3)
      • Javascript (2)
      • Bash (4)
      • Vim (9)
    • Database (3)
      • DB2 (3)
      • MongoDB (0)
    • 프레임워크 (1)
      • Ionic (1)
    • Cloud (1)
      • AWS (1)
    • 3D Printer (2)
    • 기록보관소 (5)
    • 초대장 (2)

블로그 메뉴

  • 홈
  • 태그
  • 미디어로그
  • 위치로그
  • 방명록

공지사항

  • 프로그래밍의 세계에 오신 것을 환영합니다.

인기 글

태그

  • 영어표현
  • 구피
  • typescript
  • 구피어항
  • 하프블랙구피
  • 쉘 프로그래밍
  • bash
  • 어항
  • 프로그래밍
  • AI
  • vim 강좌
  • C++
  • 리눅스 명령어
  • 영어 표현
  • 물생활
  • vim 비주얼모드
  • c강좌
  • 4차 산업혁명
  • vim
  • 생활영어
  • Linux
  • 랜섬웨어
  • bash shell
  • C언어 강좌
  • 리눅스
  • C언어
  • 딥러닝
  • call by reference
  • 인공지능
  • 영어 회화

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Peter Ahn

Peter의 우아한 프로그래밍

[Linux] chmod 로 파일 권한 변경하기
OS/Linux

[Linux] chmod 로 파일 권한 변경하기

2018. 6. 4. 18:05
반응형


개요


chmod 명령어는 리눅스의 파일이나 디렉토리의 권한을 변경하는 명령어입니다.



사용법

리눅스에서 사용되는 명령어는 모두 대소문자를 구분하니 주의해주세요.

chmod 명령어의 사용법은 다음과 같습니다.


Usage: chmod [OPTION]... MODE[,MODE]... FILE...
  or:  chmod [OPTION]... OCTAL-MODE FILE...
  or:  chmod [OPTION]... --reference=RFILE FILE...
Change the mode of each FILE to MODE.
With --reference, change the mode of each FILE to that of RFILE.

  -c, --changes          like verbose but report only when a change is made
  -f, --silent, --quiet  suppress most error messages
  -v, --verbose          output a diagnostic for every file processed
      --no-preserve-root  do not treat '/' specially (the default)
      --preserve-root    fail to operate recursively on '/'
      --reference=RFILE  use RFILE's mode instead of MODE values
  -R, --recursive        change files and directories recursively
      --help     display this help and exit
      --version  output version information and exit

Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>


기본 사용법은 아래와 같이 변경하고자 하는 권한과 파일명을 명시하여 실행하면 됩니다.

chmod 755 test.txt


리눅스 파일 권한

리눅스 파일은 user, group, others 별로 read, write, execute 권한을 부여할 수 있습니다.


ls 명령으로 현재 파일에 부여되어 있는 권한을 확인할 수 있습니다.

[Linux] ls (파일 목록 보기)


[root@peterdev ch]# ls -l
total 0
-rw-r--r-- 1 root root 0 Jun  4 08:45 test.txt


-rw-r--r-- 에서 맨앞의 - 는 file 인지 directory인지 구분하는 symbol 입니다.

[root@peterdev test]# ls -l
total 44
-rwxr-xr-x 1 root root 8576 May 10 08:38 a.out
-rw-r--r-- 1 root root  214 May 10 08:38 arr1.c
-rw-r--r-- 1 root root  425 May 10 07:30 arr.c
drwxr-xr-x 2 root root 4096 Jun  4 08:45 ch
drwxr-xr-x 2 root root 4096 May  3 14:27 john
-rw-r--r-- 1 root root    0 May  8 14:40 mv_test.dat
-rw-r--r-- 1 root root    0 May  9 06:06 new_file
-rw-r--r-- 1 root root    5 May  9 06:09 new.txt
drwxr-xr-x 2 root root 4096 May  3 14:27 peter
-rw-r--r-- 1 root root   33 May 14 09:00 test1.txt
-rw-r--r-- 1 root root   33 May  8 14:56 test2.txt

이렇게 directory인 경우에는 d 라는 symbol로 표시됩니다.


rw-r--r-- 로 표시되는 부분이 부여된 권한을 나타내는데 3개씩 끊어서 보면

앞에 3개가 user 즉 소유자(owner)의 권한이고,

중간에 3개는 group 에 대한 권한,

마지막 3개가 others 에 대한 권한이 됩니다.


이 권한을 8진수로 표현하면 rwx 권한을 다 갖는 경우 7이 됩니다.

각 권한을 숫자값으로 표현하면 r = 4, w = 2, x = 1 이기 때문에

r + w + x = 7

이렇게 되는 것이죠.


파일에 user와 group 에 대해서만 read 권한을 부여하려면 440 으로 적용하면 됩니다.


+, - 기호를 사용해서 특정 권한을 더하거나 뺄 수도 있습니다.


예제

ex) text.txt 파일에 대해서 user의 모든권한을 부여하고 group과 others는 모든 권한을 제외
chmod 700 test.txt

 

ex) text.txt 파일에 대해서 실행 권한 추가 부여
chmod +x test.txt

ex) text.txt 파일에 대해서 group에 write 권한 부여
chmod g+w test.txt
 

ex) text.txt 파일에 대해서 others의 모든 권한 박탈
chmod o-rwx test.txt
 

-Peter의 우아한 프로그래밍

여러분의 공감과 댓글은 저에게 크나큰 힘이 됩니다. 오류 및 의견 주시면 감사하겠습니다.




반응형
저작자표시 비영리 동일조건 (새창열림)

'OS > Linux' 카테고리의 다른 글

[Linux] cat 파일 내용 출력하기  (0) 2018.06.19
[Linux] 재지향(Redirection)에 대한 이해  (1) 2018.06.05
[Linux] ntpdate로 시간동기화 하기  (0) 2018.05.18
[Linux] rdate로 시간동기화 하기  (0) 2018.05.18
[Linux] 파이프(pipe)에 대한 이해  (7) 2018.05.15
    'OS/Linux' 카테고리의 다른 글
    • [Linux] cat 파일 내용 출력하기
    • [Linux] 재지향(Redirection)에 대한 이해
    • [Linux] ntpdate로 시간동기화 하기
    • [Linux] rdate로 시간동기화 하기
    Peter Ahn
    Peter Ahn
    IT 정보 공유, 프로그래밍 지식 공유

    티스토리툴바