Saturday, May 11, 2013

chmod - Change File/Directory Permissions

Command chmod  is used to change the file and directory permission in unix. It can be set only file/directory permissions by owner or superuser. The command can be used in two ways

  • Relative Permissions
  • Absolute Permissions
 ls -l                                  #display access permission for files/directories

syntax : chmod perm_mode file/dirname


RELATIVE PERMISSION

perm_mode:

   u=user,
   g=group,
   o=others

   a=all

   r   --> read
   w  --> write
   x   --> execute
 
Examples :

chmod u+x file1              #gives yourself permition to execute file1
chmod a+r *.pub             #gives read permition to everyone
chmod u+x,go+r xyz.txt  #gives execute perm to user and read permission to   group and others for the file xyx.txt

ABSOLUTE PERMISSION

value should be assigned for each mode

r  --> 4
w -->2
x  -->1

Example :

chmod 754 file1

Consider the above command file1 have the permission

Owner have have read,write and execute permission (denoted first bit 7)
Add each mode value => r+w+x= 4+2+1=7

group have read and execute permission
Add each mode value => r+w+x=4+0+1=5

others have read permission only
Add each mode value => r+w+x=4+0+0=4

chmod 754 file                #change access (rwx r-x r--)
umask 002                       (default permissions : inverse) removes write         (777-002=775)                permission for others
groups username             #to find out which group 'username' belongs to
ls -gl                                #list the group ownwership of the files
chgrp group_name directory_name/file    change the group ownwership



No comments:

Post a Comment

Price List Query for Item

 SELECT qph.list_header_id,        qph.name,        qph.description,        qphh.start_date_active,        qphh.currency_code,        q...