Linux chmod and chown two commands detailed

Source: Internet
Author: User
Tags chmod readable file permissions

Today to share 2 commands are also commonly used in our usual, chmod and chown seems to spell a bit similar, but the use of the two is different. Chmod is used to set folder and file permissions, such as our VPS host files can not read and write, you need to set 777 permissions, and Chown is used to set the user group, such as authorizing a group of users to facilitate control of user rights.

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

First, the use of rights: all users

How to use: chmod [-CFVR] [--help] [--version] Mode file ...
Description: Linux/unix file access rights are divided into three levels: file owners, groups, others. Using chmod can
To control how the file is accessed by others.

Mode: Permission set string, the format is as follows: [Ugoa ...] [[+-=][RWXX] ...] [,...], where u represents the possession of the file
, g means that the owner of the file belongs to the same group (group), O to other people, a means that all three
Is.

+ means to increase permissions,-to indicate cancellation rights, = to represent a unique set of permissions.
R means readable, W is writable, X is executable, x means only if the file is a subdirectory or the file has been
Set over to executable.
-C: Display the change action if the file permissions have actually changed
-F: Do not display error messages if the file permissions cannot be changed
-V: Show details of permission changes
-r: The same permission changes are made to all files under the current directory and subdirectories (that is, to be changed one at a time)
--HELP: Show Auxiliary Instructions
--version: Display version


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

The representative can read and write all the files in the above folder.

CD wp-content
Chmod-r 777 *

Second, the directive name: Chown

Use Rights: Root

Use mode: Chown [-CFHVR] [--help] [--version] user[:group] File ...
Description: Linux/unix is a multiple-person work system, all files are owned by the owner. Using Chown, you can use the file to hold
There are those who change. Generally speaking, this instruction is only used by System Manager (Root), the general user does not have permission to
To change someone else's file owner, there is no authority to change the file owner to someone else. Only System Manager (Root)
have such permissions.

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 the modified part is passed back
-F or –quiet or –silent: Do not display error messages
-H or –no-dereference: Only make changes to the symbolic linked file without changing any other related files
-R or-recursive: recursive processing, all files and subdirectories under the specified directory are processed together
-V or –verbose: Display instruction Execution procedure
–dereference: The effect is just the opposite of----H
–help: Show online description
–reference=< reference file or directory: The owner of the specified file or directory is set to the same group as the owner of the reference file or directory, as the owning group
–version: Display version information

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

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

The difference between chown and chmod commands

Chown Modify user and user group properties for files and folders

1. To modify the owner of the file HH.C. This user modified to Sakia all

Chown Sakia hh.c

This applies the HH.C user access rights to the Sakia as the owner

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

Chown-r Sakia:net/tmp/sco

chmod modify file and folder read and write execution properties

1. Modify the Hh.c file to writable and readable executable

chmod 777 HH.C

To modify all file attributes in a directory to be writable and read executable

chmod 777 *.*

You can 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 the directory/tmp/sco to writable and readable executable

chmod 777/tmp/sco

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

chmod 777 *

Replace the folder name with *.

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

Chmod-r 777/tmp/sco

Can write w=4
Readable r=2
Executable X=1
777 is to have full authority. Free to combine permissions on users and groups as needed

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.