Linux command: chmod command to change file or directory Access mode

Source: Internet
Author: User

chmod is a command (a combination of change mode word prefixes) and functions used in UNIX systems to control user permissions on files.
Only file owners and Superuser can modify the permissions of a file or directory. You can use the absolute mode, symbol mode to specify permissions for the file.

※ Command format

chmod [options] mode files

Mode can be expressed in digital form or in the form of who opcode permission. Who is optional and the default is a (all users). Only one opcode (opcode) can be selected. Multiple mode can be specified, separated by commas.

octal syntax
The chmod command can use octal numbers to specify permissions. The permission bit of a file or directory is controlled by 9 permission bits, each of which is a set of three bits, which are read, write, execute, read, write, execute, and other users (other) of the file owner (user). Historically, file permissions were placed in a bitmask, with the bits specified in the mask set to 1, to indicate that a class had a corresponding priority.

chmod the octal syntax for the number description:

R 4 W 2 x 1-0

The owner's authority is expressed in numbers: the sum of the numbers of the three permission bits of the master. such as rwx, that is, 4+2+1, should be 7.

The permissions of the user group are expressed in numbers: the sum of the number of permission bits that belong to the group. such as rw-, that is, 4+2+0, should be 6.

Other user's permission number expression: The sum of the numbers added to the other user's permission bits. such as R-x, that is, 4+0+1, should be 5.

※ Parameter Options

-c,--changes
only the information of the changed file is output
-f,--silent,--quiet
users who do not notify the file when chmod cannot change the file mode
-r,--recursive
recursively traverse subdirectories to modify all files and subdirectories in the directory
--reference=filename
to set permissions by referencing the permissions of the filename
-v,--verbose
output information for each file, regardless of whether the modification was successful
--version
output version information.

W.H.O.
u user
Group G
o Other
A All users (default)

OpCode
+ Add Permissions
-Delete Permissions
= Reassign Permissions

Permission
R Read
W Write
X execution
s sets the ID number of the user (or group)
T set the sticky bit (sticky bit) to prevent files or directories from being deleted by non-owner
U user's current permissions
Current permissions for Group G
o Other users ' current permissions

※ Related commands

Chown command, chown Modify the files and folders of the user and user group properties, chmod modify file and folder read and write execution properties.

The Su and sudo commands, which use the SU command to temporarily switch user identities, sudo allows the system administrator to let ordinary users perform some or all of the root commands.

※ Example of the scene

chmod u+x file adds execute permission to the owner of file

chmod 751 file assigns read, write, execute (7) permissions to the owner of file, assigns read, execute (5) permissions to the group where the file is assigned, and assigns permissions to other users to execute (1) The other form of the chmod u=rwx,g=rx,o=x file example
chmod =r file to assign Read permissions to all users
Chmod-r U+r directory recursively assigns read permissions to the owner of all files and subdirectories in the directory directory
chmod 4755 sets the ID, assigns read, write and execute permissions to the owner, and assigns read and execute permissions to the group and other users.

Refer to Wikipedia chmod

Linux command: chmod command to change file or directory Access mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.