"Linux" Directory file permissions to view and modify "Go"

Source: Internet
Author: User

Reprinted from: http://zhaoyuqiang.blog.51cto.com/6328846/1214718

--------------------------------------------------------------------------------------------------------------- ---------------------------

======================================================================================

Permissions on files on a Linux system can be viewed by right-click Properties on the file.

But we're using the full command this time. to view and modify permissions for a file

To give an example, we create a Filea file in the Mnt folder and then create a zhaoyuqiang.html Web page in the Filea folder.

Build it, we will be Filea file and zhaoyuqiang.html file for the matter, hehe

View permissions for a file

Let's take a look at the permissions of zhaoyuqiang.html this web file.

Method: In Terminal input:
ls-l xxx.xxx (xxx.xxx is the file name) is looking at the files permissions in the xxx file

Then there will be similar messages, mostly these:-rw-rw-r--

A total of 10 digits, of which: the first one-represents the type

The three rw-in the middle represent the permissions owned by the owner (user)

Then the three r--represent the permissions that the group has.

The last three r--represent the rights that other people (other) have

And then

R indicates that a 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 permission has not been granted

Then root root is the user owner.

Note : The directory problem to view file permissions: If you have a folder/a/b/c

The file that executes Ls-l/a/b view permission is not B, but the permission to view C.

Ls-l/A view of permissions for file B

Ls-l/a/b viewing permissions for C files

Ls-l/a/b/c viewing permissions for C files

Introduction to modifying Permissions

In Terminal input:

chmod o W xxx.xxx

Give other people permission to write xxx.xxx this file

chmod GO-RW xxx.xxx

Represents the deletion of read and write permissions for groups and others in xxx.xxx

which

U on behalf of owner (user)

G represents the group where the owner resides

O stands for others, but not u and g (other).

A represents all people, including U,g and O.

R indicates that a 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 be replaced by numbers

R------------4

W-----------2

X------------1

-------------0

Let's go:

Represents the Add permission

-Indicates delete permission

= indicates a permission to make it unique

When we all understand the above, then we often have some of the following permissions are easy to understand:

-RW-------(600) Only the owner has read and write permissions

-rw-r--r--(644) Only the owner has read and write permissions, and the group and other people only have Read permissions

-RWX------(700) Only the owner has read, write, execute permissions

-rwxr-xr-x (755) Only the owner has read, write, execute permissions, groups and other people only read and Execute permissions

-rwx--x--x (711) Only the owner has read, write, execute permissions, groups and other people only execute the permissions

-rw-rw-rw-(666) Everyone has access to read and write

-RWXRWXRWX (777) Everyone has access to read and write and execute

Linux file and Directory access permissions settings

Use chmod and numbers to change the access rights of a file or directory
Permissions for files and directories are represented by the rwx three characters to represent the permissions of the owner, user group, and other users. Sometimes, characters seem to be too cumbersome, so there is another way to represent permissions in numbers , and only three numbers are required.
R: Corresponding value 4
W: Corresponding value 2
x: Corresponding value 1
-: Corresponding value 0
The key to the digital setting is the value of mode, and at first many beginners will be confused, in fact very simple.

(a) We regard rwx as a binary number, if there are 1, no 0 means, then rwx r-x R-can be expressed as: 111 101 100 and then convert every three bits into a decimal number, which is 754.

(b) It can also be simply understood as an operation: (4+2+1) (4+1) (4) =754
For example, we want zhaoyuqiang.html this file to have the following permissions:
Other users of the same group as themselves
Is readable yes Yes Yes
Can be written yes Yes
Executable is
So, we first get permission string according to the above table: rw-rw-r--, then convert to binary number is 110 110 100, and then every three bits into a decimal number, we get 664, so we execute the command:

As can be seen on zhaoyuqiang.html execution 664, its permissions become

-rw-(self) rw-(same group of users) r--(other users)

According to the above rules, rwx together is 4 2 1=7, a file with a rwxrwxrwx permission, the value is 777, and the file "---------" with a completely open permission is represented as 000. Here are a few examples:
-RWX------: equals the number represents 700.
-rwxr-r--: equals the number represents 744.
-rw-rw-r-x: equals the number represents 665.
Drwx-x-x: equals the number represents 711.
DRWX------: equals the number represents 700.

Add to want to modify the permissions of all the files in a directory, including the subdirectory of the file permissions to be modified, that is, I want to modify the permissions of the FileA folder, FileA files in the permissions of the sub-files are also modified, to use the parameter-R to start the recursive processing.
For example:

For example, after modifying permission 700 on Filea, Filea's permission becomes drwx------But Zhaoyuqiang.html's permissions are still-rw-rw-r--.

, the permissions of the Filea Modify permission to-R 744, and the result Filea and its sub-file zhaoyuqiang.html are changed to-rwxr--r--。

Through the above two comparisons:

[[email protected] ~]# chmod 700/mnt/filea Note: Only set the Filea directory's permissions to 700
[[email protected] ~]# chmod-r 744/mnt/filea Note: The permissions for the entire/mnt/filea directory and its files and subdirectories are set to 744

Note that there are file problems with modifying permissions : For example, File/A/B/C.

Performed: chmod 700/a modified the permissions of a file

chmod 700/a/b modified the permissions of the B file

chmod 700/a/b/c Modify the permissions of the C file

To separate directories from the view file permissions

Use the command chown to change the ownership of a directory or file
Files and directories can not only change permissions, their ownership and user groups can also be modified, and set permissions similar to the user can be set through the graphical interface, or execute the chown command to modify.
Let's take a look at the contents of Ls-l first:

To view the permissions for the zhaoyuqiang.html file, the red area indicates that the user group zhaoyuqiang.html this file is root and the owner is root

All we have to do is modify the user group and the owner of the file.
(1) Execute the following command to transfer ownership of the zhaoyuqiang.html file to user zyq:

The user group in the red area of the file is actually changed to ZYQ.
(2) To change the owning group, you can use the following command:

We can see that we have modified the Filea folder to belong to the group Zyq.

(3) Modify the owning user group and owner of the file at the same time.

This approach, I believe we all think of

(4) To modify the owning user group and owner of Filea and its sub-file zhaoyuqiang.html at the same time.

This will use the-R parameter.

Well, the question of permissions on files is about this place.

=====================================================================================================

Reproduced this article is very comprehensive, I hope that we can have effective help, at the same time reprinted when the source of this article, respecting the original author. Thank you!!!!!!

"Linux" Directory file permissions to view and modify "Go"

Related Article

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.