Monday, May 16, 2011

using chmod command (or) Setting File permissions in Linux,Shell or Unix

chmod -is used to change the permissions for a file.
when you type the name of the file

ls -ld  - you will be able to see the permissions provided for the file

there are three groups to which permissions can be provided:
o - others
g - user group
u -users

to set the permissions for the file use:
chmod command followed by the fiename.

there are three permissions namely read,write,execute which can be given to the users,user group and others

For providing permission to a file we must be owner of the file or root
read permssion -4
write permission-2
execute permission-1

to give all permissions to a particular group such as user
provide 7=4+2+1 and no permission to usergroup and others
chmod 700 filename
ls -ld
-rwx------ 1 chris sales 4983 jan 23 22:13 ch3
 ---   ---
 user  others
1nd)r - read
2nd)w - write
3nd)x - execute

Other way to do that:
a - all users
g - owner group
u - owner user
o - others

for permissions use:

yu can either add or subtract the permissions:

assume the permission for the file to be rwxrwxrwx
permission change when each command is executed:
chmod a-w file     r-xr-xr-x
chmod o-x file     rwxrwxrw-
chmod go-rwx file  rwx------

assume the file to have a permission of ---------
chmod u+rw files   rw-------
chmod a+x files    --x--x--x
chmod ug+rw files  rw-rw----

to change the permissions for the entire directory we have to -R opton to recuresively change the permission for the entire directory

chmod -R 777 /tmp/hello/
this command willchange the perission for the entire hello directory to 777

No comments:

Post a Comment