Linux modify file and directory permissions method

Source: Internet
Author: User
Tags chmod file permissions

Syntax: chown [options] User or group file

Description: Chown changes the owner of the specified file to the specified user or group. The user can be a user name or a user ID. A group can be either a group name or a group ID. The file is a space-separated list of files that you want to change permissions for, wildcard characters are supported.

The chmod command can change permissions for all subdirectories:

To change the permissions of a file:

The code is as follows Copy Code

chmod mode File|dir

To change permissions for all subdirectories:

The code is as follows Copy Code

chmod mode Dir-r

Note that the-R parameter is appended

For example, change all files under File directory to 777:

The code is as follows Copy Code

chmod 777 File-r

To modify the permissions for all files in a directory at once, including file permissions in subdirectories, use the parameter-R representation to initiate recursive processing.

For example:

The code is as follows Copy Code

[Root@localhost ~]# chmod 777/home/user Note: Only the permissions for the/home/user directory are set to RWXRWXRWX

[Root@localhost ~]# chmod-r 777/home/user Note: Sets the permissions for the entire/home/user directory and the files and subdirectories therein to rwxrwxrwx


To modify the permissions for all files in a directory at once, including file permissions in subdirectories, use the parameter-R representation to initiate recursive processing.

For example:

The code is as follows Copy Code

[Root@localhost ~]# chmod 777/home/user Note: Only the permissions for the/home/user directory are set to RWXRWXRWX

[Root@localhost ~]# chmod-r 777/home/user Note: Sets the permissions for the entire/home/user directory and the files and subdirectories therein to rwxrwxrwx


View Directory Permissions

Statement to view file permissions:
In the terminal input:
Ls-l xxx.xxx (xxx.xxx is file name)
Then there will be similar messages, mostly these:
-rw-rw-r--
A total of 10 digits
Which: the front one-represents the type
The middle one of the three rw-represents the owner (user)
Then the three rw-represent groups (group)
The last three r--represent other people (other)
And then I'll explain the 9 digits in the back:
R indicates that the file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
-Indicates that the appropriate permissions have not been granted
Now it's time to talk about modifying file permissions.
In the terminal input:
chmod o W xxx.xxx
To give other people permission to write xxx.xxx this file
chmod GO-RW xxx.xxx
Indicates deletion of Read and write permissions for groups and other people in xxx.xxx
which
U on behalf of owner (user)
G represents the group in which the owner is located
O on behalf of others, but not u and g (Other)
A represents all the people, including U,g and O.
R indicates that the file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
Where: Rwx can also use numbers to replace
R------------4
W-----------2
X------------1
-------------0
Let's go:
Represents adding permissions
-Indicates delete permission
= means to make it a unique permission
When everyone is aware of the above, then some of our common permissions are easy to understand:
-RW-------(600) Only the owner has read and write permission
-rw-r--r--(644) Only the owner has read and write permission, the group and others only Read permission
-RWX------(700) Only the owner has access to read, write, execute
-rwxr-xr-x (755) Only the owner has the right to read, write, execute, group and others only read and execute
-rwx--x--x (711) Only the owner has permission to read, write, execute, group and others only execute
-rw-rw-rw-(666) Everyone has access to read and write
-RWXRWXRWX (777) Everyone has access to read and write and execute

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.