File PermissionsAll the three owners (user owner, group, others) in the Linux system have three types of permissions defined. Nine characters denotes the three types of permissions.
Permissions are listed below:
Permission SetLook at the above snapshot, there are ten characters (-rw-rw-r--) before the user owner. We'll describe these ten characters here. File permissions for (-rw-rw-r--)
When you are the User owner, then the user owner permission applies to you. Other permissions are not relevant to you. When you are the Group then the group permission applies to you. Other permissions are not relevant to you. When you are the Other, then the other permission applies to you. User and group permissions are not relevant to you. Permission Example Now we'll show some examples how permissions can be seen for a file or directory. Look at the above snapshot, different directories and files have different permissions. First letter (-) or d represents the files and directories respectively. Now, from remaining nine letters, first triplet represents the permission for user owner. Second triplet represents the permission for group owner. Third triplet represents the permission for other .Setting Permissions With chmodYou can change the permissions with chmod command accordingly to your need. Below are some examples to change the permissions for different groups. To add permissions to a group. Syntax: Example: Look at the above snapshot, permission to execute is added to the user owner group. To remove permissions from a group Syntax: Example: Look at the above snapshot, permission to execute is removed from the group and permission to write is removed from the user owner. To add permission to all the groups together Syntax: Example: Look at the above snapshot, we have given permission to write for all the groups. Note: Similarly, you can also remove the permission for all the groups.To add permission to all the groups without typing a Syntax: Example: Look at the above snapshot, this example is same as the earlier one only difference is that we haven't typed a in this. To set explicit permission Syntax: Example: Look at the above snapshot, we have set explicit permission to read and write for others. To set explicit permissions for different groups Syntax: Example: Look at the above snapshot, we have set permissions for all the three groups. Setting Octal PermissionsOctal permissions can also be set for the groups. For example, to set r octal will be 4, to set w octal will be 2, to set x octal will be 1. Octal Table:
From this we can conclude that, and so on. Look at the above snapshot, we have shown some random octal examples with the numbers 777, 274 and 111. umaskWhile creating a file or directory, by default a set of permissions are applied. These default permissions are viewed by umask command. For safety reasons all Unix systems doesn't provide execution permission to newly created files. Adding execution permission is upto you. mkdir -m The 'mkdir -m' command can be used to set the mode. Syntax: Example: Look at the above snapshot, we have created two files new1 and new2 with mode 777 and 000 respectively. cp -p The 'cp -p' command preserves the permissions and time stamps from source files. Syntax: Example: Look at the above snapshot, earlier permissions for files list and dupli.txt were different. But after passing the command "cp -p list dupli.txt", both the files have same permissions. Next TopicLinux chmod Command |