Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of the Linux basic command chown

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the usage of the Linux basic command chown". 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 usage of the basic Linux command chown.

Chown

Change the owner of a file or directory, or the group to which it belongs. If only one owner (user name or numeric user ID) is given, that user becomes the owner of each given file, and the group of the file is not changed. If the owner is followed by a colon and a group name (or number group ID), and there is no space between them, the group ownership of the file will also be changed. If the user name is followed by a colon but does not have a group name, make the user the owner of the file and change the filegroup to the user's login group. If a colon and group are given, but the owner is omitted, only the filegroup is changed; in this case, Chown performs the same function as chgrp. If only the colon is given, or if the entire Operand is empty, neither the owner nor the group will change.

The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Chmod [options] [owner:group] | [owner] | [.group] file

Chmod [options]-reference=RFILE file

2. List of options

Option

Description

-- version

Display command version information

-- help

Show help documentation

-c |-- changes

Same as verbose, but only show details when a change occurs

-- dereference

Modify the object referred to by the symbolic link

-h |-- no-dereference

Modify symbolic links

-- from=CURRENT_OWNER:CURRENT_GROUP

Change the owner and group of each file only if its current owner and group match the owner and group specified here. One of these two attributes can be omitted, in which case the omitted attributes do not need to match.

-- preserve-root

Recursive hype of the root directory is prohibited

-- no-preserve-root

No special treatment for root directory, default value

-f |-- silent |-- quiet

Ignore some error messages

-- reference=file

Use the group to which the associated file belongs

-v |-- verbose

Show details

-R |-- recursive

Change all directories and subdirectories recursively

-H

If the command line argument is a symbolic link to the directory, traverse it. Use with "- R".

-L

Traverse each symbolic link to the directory encountered, using it with "- R".

-P

Do not traverse any symbolic links (default), use with "- R".

3. Examples

1) change the group information by name

[root@localhost weijie] # ls-l 1.c / / the current group is weijie

-rwxr--r-- 1 rootweijie 0 September 7 09:11 1.c

[root@localhost weijie] # chown .David 1.c / / change the group to david. Pay attention to the grammar. There is a dot in front.

[root@localhost weijie] # ls-l 1.c

-rwxr--r-- 1 rootdavid 0 September 7 09:11 1.c

2) through id to modify the group information, id can be found in / etc/group

[root@localhost weijie] # ls-l 1.c / / the current group is weijie

-rwxr--r-- 1 rootweijie 0 September 7 09:11 1.c

[root@localhost weijie] # chown. 500 1. C / / change the group to 500, and the name of this id is david. Pay attention to the grammar. There is a dot in front.

[root@localhost weijie] # ls-l 1.c

-rwxr--r-- 1 rootdavid 0 September 7 09:11 1.c

3) change the owner by name

[root@localhost weijie] # ls-l 1.c / / current owner, root

-rwxr--r-- 1 rootweijie 0 September 7 09:11 1.c

[root@localhost weijie] # chown david 1.c / / change the owner to david.

[root@localhost weijie] # ls-l 1.c

-rwxr--r-- 1 davidweijie 0 September 7 09:11 1.c

4) change owner and group at the same time

[root@localhost weijie] # ls-l 1.c / / the current group is weijie

-rwxr--r-- 1 rootweijie 0 September 7 09:11 1.c

[root@localhost weijie] # chown 500 500 1.c / / change the group and owner to 500. pay attention to the syntax with a colon in the middle.

[root@localhost weijie] # ls-l 1.c

-rwxr--r-- 1 david david 0 September 7 09:11 1.c

At this point, I believe you have a deeper understanding of "the use of the Linux basic command chown". 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report