Learn about the use of chmod and Chown commands

Source: Internet
Author: User
Tags chmod readable file permissions
These two are easy to mix for beginners, where CH is actually shorthand for change, meaning:
chown-Change own changing owner
chmod-Change mod (mod doesn't know if it's abbreviated) changes file permissions

First, Chown order
Purpose: Change the owner or group of the file. The command is a combination of the word change owner.
Use examples:
1, change the owner of the file:
Chown Jim Program.c
The owner of the file program.c is changed to Jim. As an owner, Jim can use the chmod command to allow or deny other users access to PROGRAM.C.
2, change the owner of the directory:
Chown-r JOHN:BUILD/TMP/SRC
Change the owner and group of all files in the directory/tmp/src to user John and group build
-R recursively changes the owner of the specified directory and all subdirectories and files under it.
-V Displays the work done by the Chown command.
(Eg.chown–r root:root rootfs to change permissions and groups for Rootfs folder and its subdirectories to root
Chown–r Liufan:liufan-desktop Rootfs Changes the owner and group of directories Rootfs folders and subdirectories to
Household Liufan and group Liufan-desktop)

Second, chmod order
Purpose: To change the access rights of a file or directory.
There are two ways to use this command:
One is the text-setting method that contains the letters and operator expressions, and the other is the numeric setting that contains the numbers.
1. Text Setting method
chmod [who] [+ |-| =] [mode] File name
The meanings of the options in the command are:
Action object who is one of the following letters or their combination:
U represents "User", which is the owner of a file or directory.
G means "same group of users", that is, all users who have the same group ID as the owner of the file.
O Represents "other (others) users".
A represents "All users". It is the system default value.
The action symbol can be:
+ Add a permission.
-Cancels a permission.
= gives the given permission and cancels all other permissions, if any.
The permissions represented by mode set can be any combination of the following letters:
R readable.
W can be written.
X executable.
x attributes are appended only if the target file is executable for some users or if the destination file is a directory.
s the owner or group ID of the process to the file owner of the file when the file is executed. Mode "U+s" sets the user ID bit of the file, and "G+s" sets the group ID bit.
T saves the text of the program to the switching device.
You have the same permissions as the owner of the file.
G has the same permissions as the user of the same group as the file owner.
o have the same permissions as other users.
File name: A space-separated list of files to change permissions to support wildcard characters.
Multiple permissions can be given in one command line, separated by commas. For example: chmod g+r,o+r Example
Make the same group and other users have read access to the file example.
2, digital setting method
We must first understand the meaning of a number-represented attribute: 0 means no permission, 1 for executable, 2 for writable, 4 for readable, and then adds.
Therefore, the format of the numeric attribute should be 3 octal from 0 to 7, in the Order of (U) (g) (O).
For example, if you want the owner of a file to have read/write two permissions, you need to have 4 (readable) +2 (writable) =6 (read/write).
The general form of the digital setting method is:

chmod [mode] filename


Ext: http://www.aboutyun.com/thread-7675-1-1.html

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.