Two styles of chmod command format under Linux/Ubuntu

  

In Linux/Ubuntu system, the chmod command is mainly used to modify file permissions, and can use a variety of styles of command format. Today, Xiaobian will be in Linux/Ubuntu system. The style of the chmod command format is introduced to you so that you can have a more detailed understanding.

chmod

The permissions for file calls in the Linux/Ubuntu system are divided into three levels: file owner (u), group (g), and other (o). You can change the permissions of a file with chmod. Chmod is a fairly flexible command, and the modification of the permissions of the same file can be implemented in a variety of styles of command formats.

Method 1:

Syntax: chmod [-vR] mode File Name

Parameter Description:

mode permission setting string in the format [ Ugoa] [+-=] [rwx]

u means the owner of the file

g means that the owner of this file belongs to a group

o means other People

a means that the above three are the file owner (u), group (g), other (o)

+ means to increase the permissions

- means cancel Permissions

= indicates unique setting permissions

r indicates permission to read

w indicates permission to write

x indicates permission to execute

-v Display details of permission changes

-R means to make the same permission changes for all files and subdirectories in the current directory

Example:

We need to modify the permissions of the ownlinux file in the current directory to read, write, and execute the permissions of all users. Here you need to use the sudo command. If you don't know the sudo command, please take a look at the "sudo command" on this site.

ownlinux@server:/var/www$ sudo chmod a +rwx ownlinux

[sudo] password for ownlinux: (Enter your password at this time)

Or use

ownlinux@server:/var/www$ sudo chmod ugo +rwx ownlinux

[sudo] password for ownlinux: (Enter your password at this time)

The command is different, but the effect is the same after execution.

Method 2:

Syntax: chmod [-vR] [No] File Name

Parameter Description:

No Three bits represent the corresponding permissions Number

-v Display details of permission changes

-R means to make the same permission changes for all files and subdirectories under the current directory

Maybe this way for the beginning Scholars have some difficulty, but this method becomes very simple after changing the file permissions after learning. I believe that through my introduction, you will master the methods:)

First, read the corresponding number of read (r), write (w), and execute (x), as shown below.

If you remember the numbers and corresponding permissions shown above, look down

As you said earlier, the [No] parameter is three digits representing the corresponding permissions. From left to right, the first math represents the permissions of the file owner (u), the permissions of the group (g), and other (o) permissions. The number of each number that corresponds to the user of the level is the sum of the corresponding numbers of rwx. We may say not quite understand, I drew up a table to help you understand

If the above figure can be seen that all the user has to read the file, write, and execute permissions that have Permissions of (u) (4+2+1=7) Group (g) permissions (4+2+1=7) Other (o) permissions (4+2+1=7 is 777. Note : If there is no permission to read, then the corresponding number is "”0″, write (w), execute (x).

Example:

Just use the example of the first method, we need to modify the permissions of the ownlinux file in the current directory to all users have the read (r), write (w), execute (x) permissions of the file. Review the way one Command format.

ownlinux@server:/var/www$ sudo chmod a+rwx ownlinux

[sudo] password for ownlinux: (Enter your password at this time)

Method 2 command

ownlinux@server:/var/www$ sudo chmod 777 ownlinux

[sudo] password for ownlinux: ( Enter your password)

It can be seen that the command format of the second method is simple and concise

If you want to make the permissions of the file in the current directory under the ownlinux file (u) There are read (r), write (w), execute (x) permissions for the file, group (g) and other (o) users only have read (r) and execute (x) permissions to run The following command:

ownlinux@server:/var/www$ sudo chmod 755 ownlinux

[sudo] password for ownlinux: (Enter your password at this time)

This is the introduction of the chmod command format in Linux/Ubuntu system. This article mainly introduces two ways, which is more practical by comparing the second method.

Copyright © Windows knowledge All Rights Reserved