Detailed usage of Linux/Ubuntuchmod commands

Source: Internet
Author: User
When installing software using source code files in UbuntuLinux, the chmod command is often used to change the file permission so that the permission label executed during installation is Ubuntu.

It is often used to install software using source code files in Ubuntu Linux.ChmodCommand to change the permission of the file so that it has the permission to execute during installation. Because Ubuntu Linux does not use the root account to log on by default, you often need to use the sudo command to use the chmod command to change the file permission. if you do not know much about the sudo command, please take a look at the sudo command details on this site.

Chmod

Linux/UbuntuIn the system, file calling permissions are divided into three levels: file owner (u), group (g), and other (o ). You can use chmod to change the file permissions.ChmodIt is a flexible command. you can modify the permissions of the same file in multiple command formats.

Method 1:

Syntax format: chmod [-vR] mode file name

Parameter description:

Mode permission setting string, in the format of [ugoa] [+-=] [rwx]

U indicates the file owner.

G indicates that the file owner belongs to a group.

O indicates others

A indicates that the preceding three elements are file owner (u), group (g), and others (o)

+ Adds permissions.

-Indicates that the permission is revoked.

= Indicates the unique permission setting.

R indicates that you have read permission.

W indicates that you have the write permission.

X indicates that you have the execution permission.

-V: displays details about permission changes.

-R indicates that all files and subdirectories in the current directory are modified with the same permissions.

Example:

We need to set the permission of the ownlinux file in the current directory to the permission for all users to read, write, and execute the file. Here we need to use the sudo command. if you do not know much about the sudo command, please first look at the "sudo command details" on this site.

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

[Sudo] password for ownlinux: (enter your password)

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

[Sudo] password for ownlinux: (enter your password)

Commands are different, but the results are the same after execution.

Method 2:

Syntax format: chmod [-vR] [No] file name

Parameter description:

No three digits indicate the corresponding permissions

-V: displays details about permission changes.

-R indicates that all files and subdirectories in the current directory are modified with the same permissions.

This method may be difficult for beginners, but it will become very easy to change the file permissions after the methodology is completed. I believe that you will understand the following methods through my introduction :)

First, read (r), write (w), and execute (x) numbers, as shown in

If you remember the numbers shown and the corresponding permissions, you can view them.

As we have already said, the [No] parameter is a three-digit number representing the corresponding permissions. From left to right, the first math represents the permissions of the file owner (u), group (g), and other (o. Each number is the sum of the numbers corresponding to rwx. In this case, you may not quite understand it. I drew a table to help you understand it.

As you can see, if all users have the permission to read, write, and execute the file, it is the permission of the owner (u) (4 + 2 + 1 = 7) group (g) (4 + 2 + 1 = 7) Other (o) permissions (4 + 2 + 1 = 7 is 777. Note: If you do not have the read permission, the corresponding number of "r" is "0", and the write (w) and execution (x) are the same.

Example:

In this example, the ownlinux file in the current directory has the permission to read (r), write (w), and execute (x) the file). Review the command format in method 1.

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

[Sudo] password for ownlinux: (enter your password)

Method 2 Command

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

[Sudo] password for ownlinux: (enter your password)

The command format in method 2 is concise and clear.

If you want to grant the ownlinux permission to the file in the current directory to the owner (u) of the file to have the permission to read (r), write (w), and execute (x) the file, group (g) and other (o) users only have the permission to read (r) and execute (x). run the following command:

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

[Sudo] password for ownlinux: (enter your password)

I believe that you have already understood the chmod command through my introduction. I think the command style of Method 2 is easy to grasp once I understand it, and the command style of Method 2 is simple and clear.

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.