
2021년 8월 23일에 작성된 문서 1번 입니다.
linux 배운 내용을 정리했습니다.
// 폴더와 파일을 생성
mkdir linux
nano helloworld.js
// linux 폴더를 생성하고, helloworld.js 파일을 생성
ls -l 을 프롬프트에 입력하고 Enter(엔터 키)를 누르면 다음과 같은 출력을 만날 수 있다.
ls -l을 입력하면 터미널에 나타나는 출력.
username은 사용자 이름.
- 파일 helloworld.js :
-rw-r--r--- 폴더 linux :
drwxr-xr-x
- : not directory (파일) d : directory (폴더) r : read permission (읽기 권한) w : write permission (쓰기 권한) x : execute permission (실행 권한)rw-r--r-- rwxr-xr-x 
chmod로 폴더나 파일의 읽기, 쓰기, 실행 권한을 변경할 수 있다.OS에 로그인한 사용자와, 폴더나 파일의 소유자가 같을 경우에 명령어
chmod로 폴더나 파일의 권한을 변경할 수 있다.만약 OS에 로그인한 사용자와, 폴더나 파일의 소유자가 다를 경우에는 관리자 권한을 획득하는 명령어
sudo를 이용해 폴더나 파일의 권한을 변경할 수 있습니다.
chmod 로 권한을 변경하는 2가지 방법.+), 빼기(-), 할당(=)과 액세서 유형을 표기해서 변경하는 방법Symbolic method의 구분
| Access class | Operator | Access Type |
|---|---|---|
| u (user) | + (add access) | r (read) |
| g (group) | - (remove access) | w (write) |
| o (other) | = (set exact access) | x (execute) |
| a (all: u, g, and o) |
chmod 뒤에 변경할 권한을 입력. u, g, o, a를 변경할 조건에 따라 조합하여 입력액세스 클래스와 연산자, 액세스 타입을 모두 기억해야만 Symbolic method를 이용해 권한을 변경할 수 있다.
// 명령어 `chmod` 를 입력한 예시와 결과
chmod g-r filename // removes read permission from group
chmod g+r filename // adds read permission to group
chmod g-w filename // removes write permission from group
chmod g+w filename // adds write permission to group
chmod g-x filename // removes execute permission from group
chmod g+x filename // adds execute permission to group
chmod o-r filename // removes read permission from other
chmod o+r filename // adds read permission to other
chmod o-w filename // removes write permission from other
chmod o+w filename // adds write permission to other
chmod o-x filename // removes execute permission from other
chmod o+x filename // adds execute permission to other
chmod u+x filename // adds execute permission to user
// symbolic method 사용 예시
chmod a=rw helloworld.js // -rw-rw-rw-
chmod u= helloworld.js // ----rw-rw-
chmod a+rx helloworld.js // -r-xrwxrwx
chmod go-wx helloworld.js // -r-xr--r--
chmod a= helloworld.js // ----------
chmod u+rwx helloworld.js // -rwx------
// chmod 명령어와 symbolic method로
// helloworld.js 파일의 권한을 변경
rwx를 3 bit로 해석해 숫자 3자리로 권한을 표기해서 변경하는 방법rwx 가 나타나고, 각 영역의 boolean 값으로 표기할 수 있다.Absolute form 구분
| Permission | Number |
|---|---|
| Read (r) | 4 |
| Write (w) | 2 |
| Execute (x) | 1 |
만약, user는
rwx를, group과 other은r--로 권한을 변경하려고 한다면, 위 표에 나와있는 숫자의 합을 user, group, other 순으로 입력하여 사용한다.
// chmod 명령어와 Absolute form으로
// helloworld.js 파일의 권한을 변경
# u=rwx (4 + 2 + 1 = 7), go=r (4 + 0 + 0 = 4)
chmod 744 helloworld.js # -rwxr--r--
| # | Sum | rwx | Permission |
|---|---|---|---|
| 7 | 4(r) + 2(w) + 1(x) | rwx | read, write and execute |
| 6 | 4(r) + 2(w) + 0(-) | rw- | read and write |
| 5 | 4(r) + 0(-) + 1(x) | r-x | read and execute |
| 4 | 4(r) + 0(-) + 0(-) | r-- | read only |
| 3 | 0(-) + 2(w) + 1(x) | -wx | write and execute |
| 2 | 0(-) + 2(w) + 0(-) | -w- | write only |
| 1 | 0(-) + 0(-) + 1(x) | --x | execute only |
| 0 | 0(-) + 0(-) + 0(-) | --- | none |
Written with StackEdit.