Command function:
The chmod command is used to change access rights for Linux system files or directories. Use it to control access to files or directories. There are two ways to use this command. One is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.
Command format:
chmod [OPTION] ... Mode[,mode] ... File...chmod [OPTION] ... Octal---reference=rfile FILE ...
The first: Use symbolic mode, for example: chmod a+x file, where a represents all users, + represents add permission, X represents EXECUTE permission
The second type: use absolute mode, for example: chmod 777 file, which means to add readable writable executable permissions for all users, three values corresponding to three types of user
Command parameters:-c,--changes only outputs the information of the changed file-f,--silent,--quiet when chmod cannot change the file mode, the user who does not notify the file--help output help information. -r,--recursive can recursively traverse subdirectories, change the changes to all files and subdirectories in the directory--reference=filename reference the permissions of the filename to set permissions-v,--verbose regardless of the success of the modification, Outputs information for each file--version output version information. --reference=< directory or File > set to have the same permissions as the specified directory or file
--version Display version Information Command instance:
Assume that the file information in the directory is:
[Email protected]:~/test$ lltotal8DRWXRWXR-X2Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-rw-rw-r--1Vbird Vbird0September8 -: thea.txt-rw-rw-r--1Vbird Vbird0September8 -: theB.txt
1. Add files to a.txt all user groups can execute permissions (all based on the original state)
[Email protected]:~/test$ chmod A +x a.txt[email protected]:~/test$ lltotal8DRWXRWXR-X2Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-rwxrwxr-x1Vbird Vbird0September8 -: thea.txt*-rw-rw-r--1Vbird Vbird0September8 -: theB.txt
2. For a.txt simultaneous modification of different user rights, the file owner can read the writable executable, the user group is read-only, others are unreadable and non-writable. (both based on the original state)
The first method:
[Email protected]:~/test$ chmod u=rwx a.txt[email protected]:~/test$ chmod g=r a.txt[email protected]:~/test$ chmod o=A.txt[email protected]:~/test$ lltotal8DRWXRWXR-X2Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-RWXR-----1Vbird Vbird0September8 -: thea.txt*-rw-rw-r--1Vbird Vbird0September8 -: theB.txt
The second method:
[Email protected]:~/test$ chmod 740 a.txt
[Email protected]:~/test$ ll
Total 8
Drwxrwxr-x 2 Vbird vbird 4096 September 8 16:42./
Drwxr-xr-x 4 Vbird vbird 4096 September 8 16:42.. /
-RWXR-----1 Vbird vbird 0 September 8 16:42 a.txt*
-rw-rw-r--1 vbird vbird 0 September 8 16:42 b.txt
3. Set A.txt permissions based on B.txt permissions in the directory
Assume that the file information in the directory is:
[Email protected]:~/test$ lltotal ADRWXRWXR-X3Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-RWXR-----1Vbird Vbird0September8 -: thea.txt*-rw-rw-r--1Vbird Vbird0September8 -: theB.TXTDRWXRWXR-X2Vbird Vbird4096September8 -: -dir/
Workaround:
[Email protected]:~/test$ chmod--reference=b.txt a.txt[email protected]:~/test$ lltotal ADRWXRWXR-X3Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-rw-rw-r--1Vbird Vbird0September8 -: thea.txt-rw-rw-r--1Vbird Vbird0September8 -: theB.TXTDRWXRWXR-X2Vbird Vbird4096September8 -: -dir/
4. Add permissions to all files in a directory and its subdirectories, allowing others to read into the directory, but the files under the directory have read-only permissions.
Assume that the file information in the directory is:
[Email protected]:~/test$ ll
Total 12
Drwxrwxr-x 3 Vbird vbird 4096 September 8 16:52./
Drwxr-xr-x 4 Vbird vbird 4096 September 8 16:42.. /
-RWXR-----1 Vbird vbird 0 September 8 16:42 a.txt*
-rw-rw-r--1 vbird vbird 0 September 8 16:42 b.txt
DRWXRWX---2 vbird vbird 4096 September 8 16:53 dir/
[Email protected]:~/test$ ll dir
Total 8
Drwxrwxr-x 2 Vbird vbird 4096 September 8 16:53./
Drwxrwxr-x 3 Vbird vbird 4096 September 8 16:52.. /
-RW-RW----1 Vbird vbird 0 September 8 16:53 c.txt
-RW-RW----1 Vbird vbird 0 September 8 16:53 d.txt
Workaround:
[Email protected]:~/test$ chmod-r o+Rx Dir[email protected]:~/test$ lltotal ADRWXRWXR-X3Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-RWXR-----1Vbird Vbird0September8 -: thea.txt*-rw-rw-r--1Vbird Vbird0September8 -: theB.TXTDRWXRWXR-X2Vbird Vbird4096September8 -: -dir/[email protected]:~/test$ ll Dirtotal8DRWXRWXR-X2Vbird Vbird4096September8 -: -./DRWXRWXR-X3Vbird Vbird4096September8 -: the.. /-rw-rw-r-x1Vbird Vbird0September8 -: -C.txt*-rw-rw-r-x1Vbird Vbird0September8 -: -d.txt*[email protected]:~/test$ chmod o-x dir/c.txt dir/D.txt[email protected]:~/test$ lltotal ADRWXRWXR-X3Vbird Vbird4096September8 -: the./drwxr-xr-x4Vbird Vbird4096September8 -: the.. /-RWXR-----1Vbird Vbird0September8 -: thea.txt*-rw-rw-r--1Vbird Vbird0September8 -: theB.TXTDRWXRWXR-X2Vbird Vbird4096September8 -: -dir/[email protected]:~/test$ ll Dirtotal8DRWXRWXR-X2Vbird Vbird4096September8 -: -./DRWXRWXR-X3Vbird Vbird4096September8 -: the.. /-rw-rw-r--1Vbird Vbird0September8 -: -C.txt-rw-rw-r--1Vbird Vbird0September8 -: -D.txt
The chmod of Linux