Linux chmod command to modify file and folder permissions command code

Source: Internet
Author: User
Tags readable file permissions

Under various UNIX and Linux operating systems, each file (folder is also considered a file) is read, write, run set permissions.

In Linux to modify the permissions of a folder or file we need to use the Linux chmod command to do, below I wrote a few simple examples you can refer to.

The syntax is as follows:

chmod[who] [+ | - | =] [mode] 文件名

The meaning of each option in the command is

u 表示“用户(user)”,即文件或目录的所有者。 g 表示“同组(group)用户”,即与文件属主有相同组ID的所有用户。 o 表示“其他(others)用户”。 a 表示“所有(all)用户”。它是系统默认值。

The operation symbols can be:

+ 添加某个权限。 - 取消某个权限。 = 赋予给定权限并取消其他所有权限(如果有的话)。

Setting the permissions represented by mode can be any combination of the following letters:

r 可读。 w 可写。 x 可执行。

x append the x attribute only if the destination file is executable to some users, or if the target file is a directory.

s 在文件执行时把进程的属主或组ID置为该文件的文件属主。方式“u+s”设置文件的用户ID位,“g+s”设置组ID位。 t 保存程序的文本到交换设备上。 u 与文件属主拥有一样的权限。 g 与和文件属主同组的用户拥有一样的权限。 o 与其他用户拥有一样的权限。

Instance

Ways to modify a file's read-write properties

For example: Modify the index.html file to a writable, readable executable:

chmod777 index.html

To modify all the file properties under the directory writable readable executable:

chmod777 *.*

Replace the folder name with the suffix name *.
For example: Modify the properties of all HTM files:

chmod777 *.htm

Ways to modify folder properties
Modify directory/images/xiao to writable and readable executable

chmod777 /images/xiao

Modify all folder properties under the directory

chmod777 *

Replace the folder name with a *.

To modify all files and folders within a folder and subfolder properties to be writable and readable executable

chmod-R 777 /upload

Summarize the permissions differences for directories and files under Linux

File: Read file contents (r), write data to File (w), execute file As command (x).

Directory: Read the file name (R) contained in the directory, write the message to the directory (add and delete the link to the index point), search the directory (can use the directory name as the pathname to access the files and subdirectories it contains)

Specifically, that is:

(1) A user with read-only permission cannot enter the directory with a CD: You must also have Execute permission to enter.
(2) Users with Execute permission can access files in the directory only if they know the file name and have read rights.
(3) You must have read and Execute permissions to list the directory in LS, or use the CD command to enter the directory.
(4) With write permission to the directory, you can create, delete, or modify any file or subdirectory under the directory, even if the file or subdirectory belongs to another user.

View Directory Permissions

To view file permission statements:

In Terminal input:

ls-l xxx.xxx (xxx.xxx是文件名)

Then there will be similar messages, mostly these:

-rw-rw-r--

A total of 10 digits

Where: The first one – the type represented
The middle three rw-represents the owner (user)
Then those three rw-represent groups (group)
The last three R – represent others (other).

And then I'll explain the 9 digits in the back:

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

Now it's time to talk about modifying file permissions.

In Terminal input:

chmodo w xxx.xxx

Give other people permission to write xxx.xxx this file

chmodgo-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 chmod command to modify file and folder permissions command code

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.