How to Change File Ownership Group Ownership of a File In Linux

RegisterLogin
How to Change File Ownership Group Ownership of a File In Linux
Post Description: How to Change File Ownership Group Ownership of a File In Linux
Tags: how, to, change, file, ownership, , group, ownership, of, a, file, in, linux
This Post Was Posted On Jun 10, 2009 By travis #23



The following example shows a partial listing of the files in the root directory (/).





castle% cd /
castle% ls -la
total 140
drwxr-xr-x 31 root root 1024 Sep 30 13:26 .
drwxr-xr-x 31 root root 1024 Sep 30 13:26 ..
-rw------- 1 root other 205 Sep 23 10:02 .Xauthority
-rw------- 1 root root 1028 Oct 2 08:47 .cpr_config
-rw-rw-rw- 1 root other 52 Sep 26 12:19 .cshrc
drwxr-xr-x 12 root other 512 Sep 23 10:02 .dt
-rwxr-xr-x 1 root other 5111 Sep 11 10:21 .dtprofile
drwxr-xr-x 2 root root 512 Sep 11 10:21 TT_DB
-rw-r--r-- 1 root other 11 Sep 24 14:46 awk
lrwxrwxrwx 1 root root 9 Sep 10 17:58 bin -> ./usr/bin
drwxr-xr-x 5 root nobody 512 Oct 2 08:47 cdrom
drwxrwxr-x 18 root sys 4096 Oct 2 08:46 dev
drwxrwxr-x 5 root sys 512 Sep 10 18:38 devices
dr-xr-xr-x 2 root root 512 Sep 11 09:05 doe
(More information not shown)


Changing File Ownership


Use the chown command to change file ownership. Only the owner of the file or superuser can change the ownership of a file. Use the following steps to change file ownership:




1.  If you are not the owner of the file or directory, become superuser.
2.  Type chown <username> <filename> and press Return.
3.  Type ls -l <filename> and press Return to verify that the owner of the file has changed.


You can change ownership on groups of files or on all of the files in a directory by using metacharacters such as * and ? in place of filenames or in combination with them.


You can change ownership recursively by use the chown -R option. When you use the -R option, the chown command descends through the directory and any subdirectories setting the ownership ID. If a symbolic link is encountered, the ownership is changed only on the target file itself.


The following example changes the ownership of the file local.cshrc from root to winsor:





castle% ls -l local.cshrc
-rw-r�r� 1 root other 124 Sep 12 10:32 local.cshrc
castle% su
Password:
#chown winsor local.cshrc
#ls -l local.cshrc

-rw-r�r� 1 winsor other 124 Sep 12 10:32 local.cshrc
#exit
castle%




NOTE:  You can also change file ownership by specifying the UID number as the first argument to the chgrp command.



Changing Group Ownership of a File


Only the owner of the file or superuser can change the group ownership of a file. Use the chgrp command to change group ownership of a file or directory:



1.  If you are not the owner of the file or directory, become superuser.
2.  Type chgrp <groupname> <filename> and press Return.

3.  Type ls -l <filename> and press Return to verify that the group owner of the file is changed.



NOTE:  You can also change group ownership by specifying the group number as the first argument to the chgrp command.


You can change group ownership on a set of files or on all of the files in a directory by using metacharacters such as * and ? in place of filenames or in combination with them.



You can change group ownership recursively by using the chgrp -R option. When you use the -R option, the chgrp command descends through the directory and any subdirectories setting the group ownership ID. If a symbolic link is encountered, the group ownership is changed only on the target file itself.


The following example changes the group ownership of the file local.cshrc from other to staff:





castle% ls -l local.cshrc
-rw-r�r� 1 winsor other 124 Sep 12 10:32 local.cshrc
castle% chgrp staff local.cshrc
castle% ls -l local.cshrc
-rw-r�r� 1 winsor staff 124 Sep 12 10:32 local.cshrc
castle%








Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
barry
#9208 1
is chmod the same as chown?
Nov 21, 2011 Reply Report abuse
chik
#10 2
what does the 777 mean?
Jun 11, 2009 Reply Report abuse
©2012 Redoso - Tue Apr 24, 2012 8:03 am
Powered by: Webune Forums V3