In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the difference between the usage of chown and chmod commands in Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the difference between the usage of chown and chmod commands in Linux system.
Chown
Usage: chown [option]. [owner] [: [group]] file.
Or: chown [options]... -- reference= reference file file.
Change the owner and / or group of each file.
When using the-- referebce parameter, change the owner and group of the file to be the same as the specified reference file.
-c,-- changes is similar to verbose, but the results are displayed only when there are changes
-- dereference is affected by the object indicated by the symbolic link, not the symbolic link itself
-h,-- no-dereference affects the symbolic link itself, not the destination indicated by the symbolic link
(this option is useful when the system supports changing the owner of a symbolic link)
-- from= current owner: current group
Change the place only if the owner and group of each file meet the options specified.
There are people and groups. One of them can be omitted, and the omitted attribute is not.
It needs to match the original properties.
-- no-preserve-root does not treat "/" specially (default)
Preserve-root does not allow recursive operations on "/"
-f,-- silent,-- quiet removes most of the error messages
-- the reference= reference file uses the group to which the reference file belongs instead of specifying a value
-R,-- recursive recursively handles all files and subdirectories
-v,-- verbose displays diagnostic information for all files processed
The following options are used to set how to traverse the directory structure when the-R option is specified.
If you specify more than one option, only the last one will take effect.
-H if the command line argument is a symbolic link to the directory, traverse the symbolic link
-L traverses every symbolic link to the directory that is encountered
-P does not traverse any symbolic links (default)
-- help displays this help and exits
-- version displays version information and exits
If no owner is specified, it does not change. If the group is not specified, it will not be changed, but when added
When ":" the GROUP changes to the primary group of the specified owner. The owner and group can be numbers or names.
Example 1:
The code is as follows:
[root@localhost ~] # chown zhangy:zhangy nginx.conf # change users and groups to which nginx.conf belongs to zhangy,zhangy
[root@localhost ~] # ls-al | grep nginx.conf
-rw-r--r-- 1 zhangy zhangy 0 May 3 15:21 nginx.conf
[root@localhost ~] # chown-R zhangy:zhangy www # change the www directory, users and groups to zhangy,zhangy
[root@localhost ~] # ls-al | grep ww
Drwxr-xr-x 2 zhangy zhangy 4096 May 3 15:20 www # change the www directory to root
[root@localhost ~] # chown root nginx.conf
[root@localhost ~] # ls-al | grep nginx.conf
-rw-r--r-- 1 root zhangy 0 May 3 15:21 nginx.conf
Example 2:
The code is as follows:
[root@localhost database] # ll
The total dosage is 4592
-rw-r--r-- 1 root root 2466 July 23 18:02 1.html
-rw-r--r--. 1 tank tank 4099771 May 28 14:42 28toplearning.sql
-rw-r--r--. 1 tank tank 596069 May 29 00:07 toplearning.tar.gz
The code is as follows:
[root@localhost database] # chown. Changing 1.html # only changes the group
[root@localhost database] # ll
The total dosage is 4592
-rw-r--r-- 1 root tank 2466 July 23 18:02 1.html # group has changed
-rw-r--r--. 1 tank tank 4099771 May 28 14:42 28toplearning.sql
-rw-r--r--. 1 tank tank 596069 May 29 00:07 toplearning.tar.gz
Chmod
Usage: chmod [option]. Mode [, mode]. A document.
Or: chmod [options]... Octal mode file.
Or: chmod [options]... -- reference= reference file file.
Changes the mode of each file to the specified value.
-c,-- changes is similar to-- verbose, but the result is displayed only if there are changes
-- no-preserve-root does not treat the root directory specially (default)
-- preserve-root prohibits recursive operations on the root directory
-f,-- silent,-- quiet removes most of the error messages
-v,-- verbose displays diagnostic information for all files processed
-- the reference= reference file uses the mode of the specified reference file instead of specifying the permission mode
-R,-- recursive changes all files and subdirectories recursively
-- help displays this help and exits
-- version displays version information and exits
Each MODE should be of this form "[ugoa] * ([- + =] ([rwxXst] * | [ugo])) +".
Operating object
U file belongs to the primary permission
G same group user rights
O other user permissions
An all users (including the above three)
Permission setting
+ increase permissions
-revoke permissions
= unique set permissions
Permission category
R read permission
W write permission
X execution permission
X means only if the file is a subdirectory or if the file has been set to executable.
S file owner and group id
Lock the file to make it inaccessible to other users
Rmurf-> 4
WMui-> 2
Xmure-> 1
Example 1:
The code is as follows:
[root@localhost ~] # chmod ugo+r nginx_bak.conf # can be read by anyone
[root@localhost ~] # chmod astatr nginx_bak.conf # can be read by anyone
[root@localhost ~] # chmod ug+w,o-w nginx_bak.conf # is set to be the owner of the file, which can be written by those who belong to the same group, but not by others.
[root@localhost ~] # chmod uplix nginx_bak.conf # creator has execute permission
[root@localhost ~] # chmod-R astatr. / www/ # make all files and subdirectories under www readable by anyone
[root@localhost ~] # chmod Amurx nginx_bak.conf # withdraws all users' rights to execute nginx_bak.conf
[root@localhost ~] # chmod 777 nginx_bak.conf # everyone can read, write, execute
Example 2:
The code is as follows:
# chmod astats test.ppt # chmod genders to set an alternate group identity for a file
# ls-al | grep test.ppt
-rwSr-Sr--. 1 tank tank 2320384 November 18 19:29 test.ppt
The first S indicates that the user alternative identity (suid) has been set.
The second S indicates that the alternate group identity (sgid) has been set.
In this way, each user running the program will be given the same valid user identity as the program owner and the same valid group identity as the group to which the user belongs.
At this point, I believe you have a deeper understanding of the difference between the usage of chown and chmod commands in the Linux system. You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.