Overview of Unix File Access Permissions:
In this tutorial, we will get to know how to change access permissions based on individual ownership and group ownership.
The commands covered here include chmod, chown, and chgrp.
Unix Video #7:
#1) chmod: Change file access permissions.
Description: This command is used to change the file permissions. These permissions read, write and execute permission for the owner, group, and others.
Syntax (symbolic mode): chmod [ugoa][[+-=][mode]] file
The first optional parameter indicates who – this can be (u)ser, (g)roup, (o)there, or (a)ll.
The second optional parameter indicates opcode – this can be for adding (+), removing (-), or assigning (=) permission.
The third optional parameter indicates the mode – this can be (r)ead, (w)rite, or e(x)ecute.
Example: Add writes permission for user, group, and others for file1.
$ chmod ugo+w file1
Syntax (numeric mode): chmod [mode] file
The mode is a combination of three digits – the first digit indicates the permission of the user, the second digit for the group, and the third digit for others.
Each digit is computed by adding the associated permissions. Read permission is ‘4’, write permission is ‘2’ and execute permission is ‘1’.
Example: Give read/write/execute permission to the user, read/execute permission to the group, and execute permission to others.
$ chmod 751 file1
#2) chown: Change ownership of the file.
- Description: Only the owner of the file has the right to change the file ownership.
- Syntax: chown [owner] [file]
- Example: Change the owner of file1 to user2 assuming it is currently owned by the current user
- $ chown user2 file1
#3) chgrp: Change the group ownership of the file
- Description: Only the owner of the file has the right to change the file ownership
- Syntax: chgrp [group] [file]
- Example: Change group of file1 to group2 assuming it is currently owned by the current user
- $ chgrp group2 file1
Watch out for our upcoming tutorial to gain more knowledge on File Manipulation in Unix!!