Thursday 19 May 2011

chmod command


Brief: This command is used to give or change permissions to files and directories. This command will set the read, wirte and execute permissions for user, group or others.

Syntax: chmod octalnumber fileName

Command: chmod 764 myFile.txt

Description:

Chmod can be used to set below permissions
-u : User                                 -r  : Read
-g : Group                              -w : Write
-o : Others                             -e  : Execute
-a : All

Numeric Permissions: Numeric permissions can be given by a 3 digit ocatl number. 1st digit specifies the permission of a user, 2nd digit of a group and 3rd digit of others. Each octal digit has a special meaning in chmod command. The sum of the below octal numbers can be used to set read, write and execute permissions.
400 - sets the read permission for user
040 - sets the read permission for group
004 - sets the read permission for others
200 - sets the write permission for user
020 - sets the write permission for group
002 - sets the write permission for others
100 - sets the execute permission for user
010 - sets the execute permission for group
001 - sets the execute permission for others

command: chmod 764 myFile.txt
The above command sets the octal number 7 for the user , 6 for the group and 4 for others. Octal number 764 is a sum of 400+200+100+040+020+002. It means that user has got read, write and execute permissions. Group has got read and write permissions . Others have got only read permissions.

Arguments:

-f : This parameter forces the system to pass through any kind of error messages if any comes while executing chmod command
 -v : Outputs a message for every file processed

-r or -R : It is used to recursively set the permissions of files and directories within the directory.
command: chmod 644 studentDirectory

No comments:

Post a Comment