Linux chown and chmod in the difference between the two commands rounding

  • 2021-01-14 07:41:26
  • OfStack

In the linux system, the chmod and chown commands can both set permissions, but they are different; chmod is used to set the permissions of folders and files. For example, the files in our system cannot be read or written, so it needs to set the permissions of 777. chown is used to set up user groups, for example, to authorize a user group, easy to control user rights.

chmod and chown are similar in spelling, but they are used for different purposes. chmod is used to set the permissions of folders and files. For example, we need to set the permissions of 777 for files that cannot be read or written in the VPS host. ES12en is used to set up user groups, such as the authorization of a user group, easy to control user rights.

Specific use we use examples to answer, those so-called various parameter commands I do not like to share, because usually also do not use, direct use of practical.

1. Use permission: All users

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

Linux/Unix file access rights are divided into three levels: file owner, group, others. chmod allows you to control how files are accessed by others.

mode: Permission setting string in the following format: [ugoa...][[+-=][rwxX]...][,...] , where u refers to the owner of the file, g refers to those who belong to the same group as the owner of the file (group), o refers to those who are not, and a refers to all three.

+ means to increase permissions, - means to cancel permissions, = means to set permissions only 1. r means read, w means write, x means execute, X means only if the file is a subdirectory or the file has already been executed Set to executable. -c: Show the change action only if the file permissions have actually changed -f: Do not display an error message if the file permissions cannot be changed -v: Show details of permission changes -R: Permits the same permissions changes to all files and subdirectories in the current directory (i.e., recursive changes one by one) --help: Display auxiliary instructions --version: Display version

Such as: chmod -R 777 /www/itbulu.com/wp-content/*

Represents setting all files in the above folder to be read and write.


cd wp-content
chmod -R 777 *

2. Directive name: chown

Use permission: root

Usage: chown [-cfhvR] [--help] [--version] user[:group] file...

Description: Linux/Unix is a multi-person multi-work system, all files are owned. The owner of the file can be changed using chown. Generally speaking, this directive is only used by the system administrator (root). The user does not have permission to change the file owner of another person, nor does he have permission to change his file owner to another person. Only the system administrator (root) has such authority.

user: User ID for the new file owner group: User groups for new file owners (group) -c or -change: Acts like -v, but returns only the modified parts - f or � � quiet or silent: don't display error messages - h or � no - dereference: only to a symbolic link file modification, without changing any other relevant documents -R or -recursive: Recursive processing, all files in the specified directory and subdirectory 1 are processed together - v or � verbose: according to the instruction execution process Function and - h � dereference: just the opposite � help: show online � reference = < Reference files or directories > : Sets the owner and group of the specified file or directory to be the same as the owner and group of the reference file or directory � version: display version information

chown -R www:www /home/wwwroot/*

-R recursively processes all files and folders, with the first www representing the name of the owner of the file and the second www representing the name of the group to which the file belongs.

The difference between chown and chmod commands

chown modifies the user and user group properties of files and folders

1, To change the owner of hh.c. This change is owned by this user of codetc


chown codetc hh.c

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

2, Change the directory /tmp/sco to codetc and the group net


chown -R codetc:net /tmp/sco

chmod modifies file and folder read and write execution properties

1, Change hh.c file to write, read and execute


chmod 777 hh.c

To change all file properties in a directory to be writable, readable and executable


chmod 777 *.*

Substitute * for folder names and suffix names.

Similarly, if you want to modify the properties of all htm files


chmod 777 *.htm

2, Change the directory /tmp/sco to write, read and execute


chmod 777 /tmp/sco

To change all folder properties in a directory to be writable, readable and executable


chmod 777 *

Just use a * for the folder name

To modify all files and folders and their subfolders under /tmp/sco to be writable, readable and executable


chmod -R 777 /tmp/sco

Can write w = 4

Readable r = 2

The executable x = 1

The 777 is full access. You are free to combine user and group permissions as needed

conclusion


Related articles: