Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

Changing the ownership of files and directories

Changing the ownership of files and directories

To change the ownership of a file or directory, use the chown command.
If you want to change the ownership of all files in a directory, run it with the -R option.

●Changing the ownership of files and directories

[root@Lion ~]# ls -l /home/nuy/
total 55
drwx------ 5 nuy nuy 4096 Sep 5 12:24 Maildir/
drwxr-xr-x 3 nuy nuy 4096 Sep 5 10:41 lib/
drwxr-xr-x 7 nuy nuy 4096 Sep 5 10:41 rpm/
drwxr-xr-x 2 nuy nuy 4096 Sep 12 14:57 sampdir/
drwxrwxr-x 2 nuy nuy 4096 Sep 12 15:00 sampdir2/
-rw-r--r-- 1 nuy nuy 0 Sep 12 14:58 samptxt
-rw-rw-r-- 1 nuy nuy 0 Sep 12 15:01 samptxt2
↑ Ownership is nuy

[root@Lion ~]# chown -R root:root /home/nuy/ ←Execute the chown command to make the ownership root
[root@Lion ~]# ls -l /home/nuy/
total 55
drwx------ 5 root root 4096 Sep 5 12:24 Maildir/
drwxr-xr-x 3 root root 4096 Sep 5 10:41 lib/
drwxr-xr-x 7 root root 4096 Sep 5 10:41 rpm/
drwxr-xr-x 2 root root 4096 Sep 12 14:57 sampdir/
drwxrwxr-x 2 root root 4096 Sep 12 15:00 tsampdir2/
-rw-r--r-- 1 root root 0 Sep 12 14:58 samptxt
-rw-rw-r-- 1 root root 0 Sep 12 15:01 samptxt2

●Change ownership of files in a directory to a different user

[root@Lion ~]# ls -l sampdir ←View information about the files in the directory and check that they are owned by nuy
total 0
-rw-r--r-- 1 nuy nuy 0 Sep 4 10:23 samptxt1
-rw-r--r-- 1 nuy nuy 0 Sep 4 10:23 samptxt2
-rw-r--r-- 1 nuy nuy 0 Sep 4 10:23 samptxt3

↑ Ownership is nuy

[root@Lion ~]# chown -R root.root /home/nuy/sampdir/
↑Execute the chown command to make the ownership of the files in the directory root as well
[root@Lion ~]# ls -l chown sampdir
↑View the files in the directory again and make sure that the permissions are set to root

total 0
-rw-r--r-- 1 root root 0 Sep 4 10:23 samptxt1
-rw-r--r-- 1 root root 0 Sep 4 10:23 samptxt2
-rw-r--r-- 1 root root 0 Sep 4 10:23 samptxt3
Copied title and URL