본문 바로가기

리눅스-기초명령어/파일 및 유저 권한

chown

파일 및 디렉토리에 대한 소유권을 변경

chown [옵션] [user:group] [파일]

 

옵션

-R : 하위 파일의 소유자 ,소유그룹을 전부 변경한다

[root@Linux ~]# chown -R admin AAA
[root@Linux ~]# ll
total 56
drw-rwxr-x. 2 admin root  45 Apr 27 12:25 AAA
[root@Linux ~]# cd AAA
[root@Linux AAA]# ll
total 0
-rw-r-----. 1 admin admin 0 Apr 27 12:25 A.txt
-rw-r-----. 1 admin root  0 Apr 27 12:25 B.txt
-rw-r-----. 1 admin root  0 Apr 27 12:25 C.txt

소유자 권한이 전부 admin으로 바뀌었다.

 

-h : 심볼릭 링크 파일의 소유자와 그룹을 바꾼다.

[root@Linux ~]# ll
total 56
lrwxrwxrwx. 1 root root  15 Apr 27 13:10 ABC -> /root/AAA/A.txt
[root@Linux ~]# chown -h admin ABC
[root@Linux ~]# ll
total 56
lrwxrwxrwx. 1 admin root  15 Apr 27 13:10 ABC -> /root/AAA/A.txt

 

-v : 실행된 내용을 자세히 출력해준다.

[root@Linux ~]# chown -v root ABC
changed ownership of 'ABC' from admin to root

 

-c : 변경된 내용을 출력해준다.(변경 사항이 생겼을때만 출력)

[root@Linux ~]# chown -c admin ABC
changed ownership of 'ABC' from root to admin

 

예시

소유자의 소유권을 변경할 경우 ( 그룹을 따로 지정하지 않으면 바뀌지 않는다)

[root@Linux AAA]# ll
total 0       #현재 소유권은 admin
-rwxrwx--x. 1 admin admin 0 Apr 27 12:25 A.txt
[root@Linux AAA]# chown root A.txt   #A.txt에 소유권을 root로
[root@Linux AAA]# ll
total 0       소유권이 admin에서 root로 바뀌었다.
-rwxrwx--x. 1 root admin 0 Apr 27 12:25 A.txt

소유권이 admin에서 root로 바뀌었다

 

그룹만 소유권을 변경 할 경우 : 를 사용하면 그룹만 변경이 가능해진다

[root@Linux AAA]# ll
total 0
-rwxrwx--x. 1 root admin 0 Apr 27 12:25 A.txt
[root@Linux AAA]# chown :root A.txt # :명령어는 그룹만 변경할때 사용
[root@Linux AAA]# ll
total 0
-rwxrwx--x. 1 root root 0 Apr 27 12:25 A.txt

원래 그룹의 소유권은 admin이였지만 명령어를 통해 root로 바뀌었다.

 

'리눅스-기초명령어 > 파일 및 유저 권한' 카테고리의 다른 글

ACL (Access Control List)  (0) 2023.09.01
umask  (0) 2023.09.01
chgrp  (0) 2023.08.31
chmod  (0) 2023.08.31