Raspberry Pi_Eng_13.2.1 Changing Owner User and Owner Group of File


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


13.2   Changing Permission on File

 

13.2.1  Changing Owner User and Owner Group of File

 

13.2.1.1    "chown" Command Change Owner User of File

 

To change the owner user of a file, use the "chown" command. You can change the owner user information, and if necessary, change the owner group for the file at the same time.

 

[Command Format]

chown  [OPTION]... [OWNER] [:[GROUP]]  FILE...

 

[Command Overview]

   This changes the owner user of a file.

   User privilege          -- Super user.

 

[Detail Description]

   This command changes the owner user and owner group for a specific file. You can change only the owner user, or change the owner group together. 

   When changing a owner group, execute the command in the format ": group name". If you specify only a colon (:) and do not specify a group name, it is changed to the primary group of the owner user.

 

[Main Option]

--help

display this help and exit

-R, --recursive

operate on files and directories recursively

When working on a directory, all of the subdirectorys and files under the directory are changed at once

 

 

[Used Example]

To change the owner user of directory "manual01" to "root", do the following task.

 

pi@raspberrypi ~ $ sudo chown root ./testdata/manual01

 

 

If you view the details of the file again after the operation is completed, you can see that the owner for "manual01" has been changed to "root".

 

pi@raspberrypi ~ $ ls ./testdata/ -l

total 16

drwxr-xr-x 2 root pi 4096 Mar 24 02:26 manual01

drwxr-xr-x 2 pi   pi 4096 Mar 24 02:26 manual02

-rw-r--r-- 1 pi   pi   18 Mar 24 02:10 user_guide01.txt

-rw-r--r-- 1 pi   pi   18 Mar 24 02:10 user_guide02.txt


 

13.2.1.2    "chgrp" Command - Change Owner Group of File

 

Owner group of a file can be changed using the "chgrp" command.

 

[Command Format]

chgrp  [OPTION]...  GROUP   FILE...

 

[Command Overview]

   This changes the owner group of a file

   User privilege          -- Super user.

                                        

[Detail Description]

   None

 

[Main Option]

--help

display this help and exit

-R, --recursive

operate on files and directories recursively

When working on a directory, all of the directorys and files under the directory are changed at once

 

[Used Example]

To change the owner group for directory "manual01" to "root", do the following task.

 

pi@raspberrypi ~ $ sudo chgrp root ./testdata/manual01

 

If you check the details of the file again after the operation is completed, you can see that the owner group for "manual01" has been changed to "root".

 

pi@raspberrypi ~ $ ls ./testdata/ -l

total 16

drwxr-xr-x 2 root root 4096 Mar 24 02:26 manual01

drwxr-xr-x 2 pi   pi   4096 Mar 24 02:26 manual02

-rw-r--r-- 1 pi   pi     18 Mar 24 02:10 user_guide01.txt

-rw-r--r-- 1 pi   pi     18 Mar 24 02:10 user_guide02.txt