Modify folder permissions under Ubuntu

Source: Internet
Author: User
Tags readable

Common methods are as follows:

sudo chmod 600xxx (only the owner has read and write permissions)
sudo chmod 644xxx (owner has read and write permissions, group user only Read permissions)
sudo chmod 700xxx (only the owner has read and write and Execute permissions)
sudo chmod 666xxx (everyone has access to read and write)
sudo chmod 777xxx (everyone has access to read and write and execute)

where xxx refers to the file name (can also be a folder name, but to add-ld after chmod).

Explain the fact that the whole command is in the form
sudo chmod-(on behalf of type) XXX (owner) xxx (group user) xxx (other users)

Each of the three-digit digits represents a user-type permission setting. The value is 0~7, which is the binary [000]~[111].

Each bit of this three-bit binary number represents read, write, and execute permissions respectively.

If 000 means none of the three permissions, and 100 means read-only. In this way, we have the following correspondence:
0 [000] no permissions
4 [100] read-only permission
6 [110] Read and Write permissions
7 [111] Read and write execution permissions

Now look at some of the common usage above is very clear. Try to modify the permissions yourself.

Finally, attach the command to query the file (or folder) permissions.
Ls-l file name (folder will change-L to-ld).

Let's look at the file properties first.
Enter in the shell environment: ls-l can view the current directory file. Such as:
Drwxr-xr-x 2 NSF users 1024 12-10 17:37 download file backup
respectively, the corresponding is:
File attribute Connection number file owner group file Size file modified time file name
Here r is readable, W writable, x executable, where file attributes are divided into four segments,----------10 positions
For example:
D rwx R-x R-x
The first character specifies the file type. In the usual sense, a directory is also a file. If the first character is a horizontal line, it represents a non-directory file. If it is D, the representation is a directory.
The second paragraph is the property of the owner of the file,
The third paragraph is the attribute of the group to which the file belongs.
The fourth paragraph is for the properties of other users,
As the above folder "download file backup" Access rights, indicating that the folder "download file backup" is a directory file, folder "Download file backup" owner has read and write executable permissions, and the folder "download file backup" belong to the main group of users only read and execute permissions, other users also have read and execute permissions.
After determining the access rights of a file, users can use the chmod command provided by the Linux system to reset different access rights. You can also use the Chown command to change the owner of a file or directory. Use the CHGRP command to change the user group for a file or directory.
chmod command
function: The chmod command is very important for changing the access rights of a file or directory. Users use it to control access to files or directories.
Syntax: This command has two uses. One is a text-setting method that contains letters and operator expressions, and the other is a digital setting method that contains numbers.
1. Text Setting method
chmod [who] [+ |-| =] [mode] file name?
Parameters:
Action object who is either or a combination of the following letters:
U means "user", which is the owner of the file or directory.
G means "same group user", that is, all users who have the same group ID as the file owner.
O means "other (others) users".
A means "all users". It is the system default value.
The operation symbols can be:
+ Add a permission.
-Cancels a permission.
= gives the given permission and cancels all other permissions, if any.

Setting the permissions represented by mode can be any combination of the following letters:
R is readable.
W writable.
X executable.
x append the x attribute only if the destination file is executable to some users, or if the target file is a directory.
S is the owner of the file in which the owner or group ID of the process is placed when the file is executed. The way "U+s" sets the user ID bit of the file, "G+s" sets the group ID bit.
T save the program's text to the swap device.
You have the same permissions as the owner of the file.
G has the same permissions as a user with the same group as the file owner.
o have the same permissions as other users.
File name: A list of files separated by spaces to change permissions, and wildcard characters are supported.
Multiple permission methods can be given in one command line, separated by commas. Example: chmod g+r,o+r Example
Enables the same group and other users to have read access to the file example.
CHGRP command
Function: Change the group to which the file or directory belongs.
Syntax: CHGRP [options] group filename?
This command changes the user group to which the specified file belongs. Where group can be the user group ID or the group name of the user group in the/etc/group file. The file name is separated by a space to change the list of files belonging to the group, support wildcard characters. If the user is not the owner or superuser of the file, you cannot change the group of the file.
Parameters:
-R recursively changes the genus of the specified directory and all subdirectories and files under it.
Example 1:$ chgrp-r Book/opt/local/book
Change the genus of all files under/opt/local/book/and its subdirectories as book.
Chown command
Function: Change a file or directory's owner and owner group. This command is also very common. For example, the root user copies a file of his own to the user Xu, in order for the user Xu to access the file, the root user should be the owner of the file to Xu, otherwise, the user Xu cannot access the file.
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 either 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 to change permissions, and wildcard characters are supported.
Parameters:
-R recursively changes the owner of the specified directory and all subdirectories and files under it.
-V shows the work done by the Chown command.
Example 1: Change the owner of the file shiyan.c to Wang.
$ chown Wang Shiyan.c
Example 2: Change the owner of the directory/his and all files and subdirectories under it to Wang, and change the group to users.
$ chown-r Wang.users/his

Modify folder permissions under Ubuntu

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.