Search This Blog

Wednesday, April 2, 2014

Chown, Chgrp and Chmod Introduction

1) chown :  change file owner and group
To check the ownership of a file or directory use ls -l
Usage: chown [-Rcfv] newowner filenames/directory. Take note only root can change the ownership.
Example:
chown linda file.txt
This will cause file.txt to now be owned by linda.
chown -R abu:sales /home/account/
This is going to make all files inside /home/account/ and its subdirectories to belong to abu and to be associated with the group sales. -R means include all subdirectories
.
2) chgrp : change group ownership 
Usage : chgrp [-Rcfv] groupname foo.txt
Example:
chgrp marketing file.txt - to change the group specified to a certain document
chgrp oracle /usr/database – to change the group specified to a certain directory
chgrp -R marketing /sales/2008 – to change the group specified to a certain directory recursively
.
3) chmod : to change the permissions of a file or directory. Use ls -l to see the permission settings.
Below is how the permission is assigned.
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000

and so on...

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4
For example, if we wanted to set some_file to have read and write permission for the owner, but wanted to keep the file private from others, we would:
chmod 600 some_file

My Profile

My photo
can be reached at 09916017317