Linux: chmod: chown application instance

Source: Internet
Author: User

Command name: chmod

Permission: All Users

Usage: chmod [-CFVR] [-- help] [-- version] mode file...

Note: file access permissions for Linux/Unix are classified into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Calculation:

Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxx]...] [,...],
U indicates the owner of the file, G indicates that the owner of the file belongs to the same group, O indicates that the owner of the file belongs to other people, and a indicates that all three are.

+ Adds a permission,-Indicates canceling the permission, and = indicates a unique permission.

R indicates that the file can be read, W indicates that the file can be written, and X indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable.

-C: if the permission of the file has been changed, the change action is displayed.

-F: Do not display an error message if the file permission cannot be changed.

-V: displays details of permission changes.

-R: Change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)

-- Help: displays auxiliary instructions

-- Version: displays the version.

Example: Set the file file1.txt to readable by all users:
Chmod Ugo + R file1.txt

Set file1.txt to readable:
Chmod A + R file1.txt

Set file1.txt to read/write:
Chmod A + W file1.txt

Set file1.txt and file2.txt as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:
Chmod ug + W, o-w file1.txt file2.txt

Set ex1.py to only the owner of the file to execute:
Chmod U + x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:
Chmod-r a + R *

In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.
Syntax: chmod ABC File

Each A, B, and C is a number, indicating the permissions of the user, group, and other respectively.

(Read) r = 4, (write) W = 2, (execute) x = 1

If the rwx attribute is required, 4 + 2 + 1 = 7; (read, write, and execute)

If the RW-attribute is required, 4 + 2 = 6; (read, write)

If you want the R-x attribute, 4 + 1 = 5. (Read, execute)

Example:
Chmod A = rwx file and chmod 777 file have the same effect as chmod + 755

Chmod ug = rwx, O = X file, and chmod 771 file have the same effect.

If you use chmod 4755 filename, you can grant root permissions to this program.

Usage: chmod [-cfhvr] [-- help] [-- version] user [: Group] file...

Note: Linux/Unix is a multi-person, multi-job operating system. All archives have owners.
Chown can be used to change the owner of an archive. Generally, this command is only used by the system administrator (Root). Generally, users do not have the permission to change the owner of another user's archive or change their owner to another user. Only the system administrator (Root) has such permissions.

 

Chown

1. Role
Change the owner and group of one or more files or directories. The permission is a Super User.

2. Format
Chown [Option] user or group file

3. Main Parameters
-- Dereference: The objects indicated by symbolic links are affected, not the symbolic links themselves.
-H, -- no-dereference: affects the symbolic link itself, rather than the destination indicated by the symbolic link (this option is valid only when the system supports changing the owner of the symbolic link ).
-- From = Current Owner: the current group changes the owner and group only when the owner and group of each file meet the specified options. One of these attributes can be omitted. The omitted attributes do not need to conform to the original attributes.
-F, -- silent, -- Quiet: removes most error messages.
-R, -- Recursive: recursively processes all files and subdirectories.
-V, -- verbose: displays information when processing any file.

4. Description
Chown changes the owner of a specified file to a specified user or group. The user can be the user name or user ID, and the group can be the group name or group ID; files are separated by spaces to change the permission list. Wildcards are supported. The system administrator often uses the CHOWN command to grant the user the permission to use the file after copying the file to another user's directory.

5. Application Instance
1. Change the owner of the Shiyan. c file to Wan
$ Chown Wan Shiyan. c

2. Change the owner of the directory/Hi and all files and subdirectories to Wan and the group to users.
$ Chown-r Wan. Users/hi
 

 

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.