ChmodIs a Command Used in UNIX systems to control the user's permissions on files (ChAngeMoDA combination of e-word prefixes) and functions. Only the file owner and the Super User can modify the file or directory permissions. You can use absolute mode to specify the object ACL in symbolic mode.
Usage
ChmodUse syntax
$ chmod [options] mode[,mode] file1 [file2 ...]
Use the LS command to view the properties of a file or directory
$ ls -l file
Octal syntax
ChmodYou can use the octal number to specify the permission. The permissions of a file or directory are controlled by nine permissions, each of which is a group of three. They are the reading, writing, and execution of the file owner (user), and the user group (group) read, write, execute, and read, write, and execute (other) other users. Historically, the File Permission is placed in a bit mask, and the bit specified in the mask is set to 1. In this case, a class has a corresponding priority.
ChmodA Numerical Description of the octal Syntax;
R 4
W 2
X 1
-0
The owner's permissions are expressed in numbers: the sum of the three permission bits of the owner. For example, rwx, that is, 4 + 2 + 1, should be 7.
The permissions of a user group are expressed by numbers: the sum of the number of the permissions of the group. For example, RW-, 4 + 2 + 0, should be 6.
The number of permissions of other users indicates the sum of the numbers of other user permission bits. For example, R-X, that is, 4 + 0 + 1, should be 5.
For example, modify the file myfile permission.
$ chmod 664 myfile$ ls -l myfile-rw-rw-r-- 1 57 Jul 3 10:13 myfile
Symbol Mode
You can set multiple projects in symbolic mode: WHO (user type), operator (operator), and permission (permission). The setting of each project can be separated by commas. The command chmod modifies the access permission of the user type specified by WHO to the file. The user type is indicated by the location of one or more letters in WHO, as shown in the WHO symbol mode table:
Who |
User Type |
Description |
U |
User |
File owner |
G |
Group |
File owner Group |
O |
Others |
All other users |
A |
All |
User used, equivalentUgo |
Operator symbol mode table:
Operator |
Description |
+ |
Add permissions for the specified user type |
- |
Remove permissions of the specified user type |
= |
Set the specified user permission to reset all permissions of the User Type |
Symbol mode table of permission:
Mode |
Name |
Description |
R |
Read |
Set as read permission |
W |
Write |
Set to writable |
X |
Execution permission |
Set as executable permission |
X |
Special execution permission |
The file permission can be set to executable only when the file is a directory file or other types of users have executable permissions. |
S |
Setuid/GID |
When an object is executed, set the setuid or setgid permission for the object based on the user type specified by the WHO parameter. |
T |
Paste bit |
Set the position to be pasted. Only the Super User can set this bit. Only the file owner u can use this bit. |
Symbol mode instance
Owner of the DirectoryUAnd associated groupGAdd readRAnd writeWPermission:
$ chmod ug+rw mydir$ ls -ld mydirdrw-rw---- 2 unixguy uguys 96 Dec 8 12:53 mydir
All users of the fileUgoDelete writeWPermission:
$ chmod a-w myfile$ ls -l myfile-r-xr-xr-x 2 unixguy uguys 96 Dec 8 12:53 myfile
PairMydirOwnerUAnd associated groupGSet to readRAnd executableXPermission:
$ chmod ug=rx mydir$ ls -ld mydirdr-xr-x--- 2 unixguy uguys 96 Dec 8 12:53 mydir
Command to use instances
Command |
Description |
Chmod A + RFile |
Add read permission to all users of the file |
Chmod A-xFile |
Delete all users who execute the file |
Chmod A + RWFile |
Add read/write permissions to all users of the file |
Chmod + rwxFile |
Add the read/write permission to all users of the file. |
Chmod u = RW, go =File |
Set the read and write permissions for the file owner, clear all permissions for the file user group and other users |
Chmod-r u + R, go-RDocs |
Add read permissions for all users to the directory docs and all files in its subdirectory hierarchy, and delete read permissions for user groups and other users. |
Chmod 664File |
Set the read and write permissions for the file owner and user group, and set the read permissions for other users. |
Chmod 0755File |
EquivalentU = rwx (4 + 2 + 1), go = rx (4 + 1 & 4 + 1).0No special mode. |
Chmod 4755File |
4SetSet User IDBit. The rest is equivalent to u = rwx (4 + 2 + 1) and go = rx (4 + 1 & 4 + 1 ). |
Find path/-type D-exec chmod A-x {}\; |
Delete all users with executable permissions on path/and all its directories (excluding files), and use '-type F' to match the file |
Find path/-type D-exec chmod A + x {}\; |
Allow all users to browse or use the directory path/ |