chmod and Chown two commands in Linux

Source: Internet
Author: User
Tags readable file permissions

In the Linux system, Chmod,chown commands can be set permissions, but they are also different, the following small section for you to introduce chmod and chown two command usage and differences introduced.

Today's 2 commands to share are also commonly used by us, chmod and Chown seem to have a somewhat similar spelling, but the use of the two is different. Chmod is used to set folder and file permissions, such as our VPS host file is not read and write, need to set up 777 permissions, and Chown is used to set up user groups, such as authorized a user group, easy to control user rights.

Concrete use We use examples to answer, those so-called various parameters command I do not like to share, because usually also can not use, directly with the practical.

First, use Rights: all users

Mode of use: chmod [-CFVR] [--help] [--version] Mode file ...
Description: Linux/unix file access rights are classified into three levels: file owners, groups, and others. The use of chmod can be
To control how files are accessed by others.

Mode: Permission set string in the following format: [Ugoa ...] [[+-=][RWXX] ...] [,...], where u represents the ownership of the file
, g means that the owner of the file belongs to the same group (group), and O means the other person, a means that all three
Is.

+ indicates an increase in permissions,-represents a cancellation permission, = Represents a unique set of permissions.
R means readable, w means writable, x is executable, x means only if the file is a subdirectory or the file has been
has been set to be executable.
-C: If the file permissions have changed, the change action will be displayed
-F: Do not display an error message if the file permissions cannot be changed
-V: Show details of permission changes
-r: The same permissions change for all files in the current directory and subdirectories (that is, they are changed in a recursive manner)
--HELP: Show Auxiliary Instructions
--version: Display version


For example: Chmod-r 777/www/itbulu.com/wp-content/*

The representative sets all the files in the above folder to read and write, or you can do so.

CD wp-content
Chmod-r 777 *

Second, directive name: Chown

Usage rights: Root

How to use: Chown [-CFHVR] [--help] [--version] user[:group] File ...
Description: Linux/unix is a multi-person and multi-work system, with all files owned by the owner. with Chown, the archive can be
The people who have changed . Generally speaking, this instruction is only used by the system administrator (root), the general user does not have the authority to
Change other people's file owner, also do not have the authority to change the owner of their own files to other persons. Only system administrator (root)
have this permission.

User: The user ID of the new file owner
Group: The user group of the new file owner (group)
-C or-change: The function is similar to-V but only returns the modified part
-F or –quiet or –silent: Do not display error messages
-H or –no-dereference: Only modify the symbolic linked files without changing any other related files
-R or-recursive: recursively handles all files and subdirectories under the specified directory
-V or –verbose: show instruction execution process
–dereference: The effect is just the opposite of-H
Help: Show online instructions
–reference=< reference file or directory;: Set the owner of the specified file or directory and the owning group to the same owner of the referenced file or directory as the owning group
–version: Display version information

Chown-r www:www/home/wwwroot/*

Explanation:-R recursively handles all files and folders, the first WWW represents the name of the owner of the file, and the second WWW represents the group name.

The difference between chown and chmod commands

Chown Modifying the user and user group properties of files and folders

1. The owner of the file hh.c to be modified. Modify this user for Sakia all

Chown Sakia hh.c

This applies hh.c user access rights to Sakia as the owner

2. Change the directory/tmp/sco owner and group of this directory to Sakia and group net

Chown-r Sakia:net/tmp/sco

chmod modifying file and folder read and write execution properties

1. Modify the Hh.c file to a writable, readable executable

chmod 777 HH.C

To modify all file properties under a directory to be writable and readable executable

chmod 777 * *

Replace the folder name with the suffix name *.
Similarly, if you want to modify the properties of all HTM files

chmod 777 *.htm

2. Modify directory/tmp/sco to writable and readable executable

chmod 777/tmp/sco

To modify all folder properties under a directory to be writable and readable executable

chmod 777 *

Replace the folder name with a *.

To modify all files and folders and their subfolder properties under/tmp/sco as writable and readable executable

Chmod-r 777/tmp/sco

Can write w=4
Readable r=2
Executable X=1
777 is to have full access. Ability to freely combine user and group permissions as needed

chmod and Chown two commands in Linux

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.