File Permission
Description :
- In this example, the file named service is an ordinary file.
- The owner named simon of this file has the permission of read, write and execute.
- The members in group named in have the permission of read and execute.
- The other users have the permission of read.
- If we name yes as 1 and no as 0, then rwx is yesyesyes, accordingly the permission of the owner is 111 in binary (7 in decimal).
- And the permission of the group is 101 in binary (5 in decimal), the permission of others is 100 in binary (4 in decimal)
- In this way, we can say the permission of this file is 754.
- There are three types : readable, writable, executable . For example , a user wants to copy a file to the other directory, the file should have the readable permission and the directory should have the writable permission for this user.
-----------------------------------------------------------------------------------------------------------------------
chmod
Syntax :
- chmod numberic_mode file - Change file mode access permissions
Examples:
# chmod 664 file1
Change the access permissions of file1 to 664 (rw- rw- r--)
--------------------------------------------------------------------------------------------------------------------
chown, chgrp
Syntax :
- chown [-R] owner [:group] file - Change file owner or group
- chgrp [-R] group file - Change file group
Examples:
# chown mark: users design_notes
The command searches the directory design_notes and changes the files in the directory to be owned by users which is grouped in mark
# chown users design_notes
The command searches the directory design_notes and changes the file design_notes to be owned by users
Description :
- -R (Recursive) : chown descends through the directory, and any sub-directories, Setting the ownership ID as it proceeds. When a symbolic link is encountered, the owner of the target file is changed(unless the -h option is specified) , but no recursion takes place.
-----------------------------------------------------------------------------------------------------------------
umask
Syntax :
- umask [-s] [mode]- user file-creation mode mask
Examples:
user group other
default permission : rw- rw- rw-
set default permissions: rw- r-- ---
$ umask g=r , o=
Description:
- In UNIX, the system calls have base permissions (sometimes referred to as "default permissions") with which to create new files and directories.
- For directories the base permissions are (octal) 777 (rwxrwxrwx), and for files they are 666 (rw-rw-rw).
- Before creating the file or directory, the base permissions are compared to a mask (the umask set by the umask command) that will "mask out" permission bits to determine the final permissions for the object being created.
- The calculation to determine the final permissions is to take the binary of the base permissions and perform a logical AND operation on the ones complement representation of the binary umask.
- Here is an example for creating a file with a umask of 022: The binary representation for octal 022 is 000010010. The ones complement simply inverts the numbers to make zeros equal ones and ones equal zeros, resulting in 111101101. Now if we perform a logical AND with the base permissions of 666 (binary 110110110) we end up with 644 (binary 110100100) , as in the following example:
110110110 : base permissions of 666
111101101 : ones complement of a umask of 022
---------------- perform logical AND, two 1s equal 1, everything else equals 0
110100100 : This converts to octal 644 which is rw-r--r--
- Instead of performing the binary operation above, we can simply subtract the umask from the base permissions to determine the result. For the previous example, we would do the following :
666 Base permissions
022 umask value
----- subtract
644 permission of new file (rw-r--r--)
----------------------------------------------------------------------------------------------------------------------
touch
Syntax :
- touch [-amc] file .... - Update access and/or modification times of file
Examples:
0 comments:
Post a Comment
If there is any comments,Please leave a comment at here.