Chown commands in Linux

Source: Internet
Author: User

Chown The owner of the specified file to the specified user or group, the user can be either a user name or a user ID; a group can be a group name or a group ID; a file is a space-separated list of files to change permissions, and wildcard characters are supported.   System administrators often use the Chown command to give users permission to use a file after copying it to another user's directory. 1. Command format: chown [options] ... Owner  [: [Group]] file ... 2. Command function: Change the file owner and group by Chown. You can use the user name and user identification number settings when you change the owner or group of the file. Ordinary users cannot change their files to other owners.  Its operation permissions are generally administrators. 3. Command parameters:-C Displays information about the changed section-F ignores error message-H fix symbolic link-R handles all files in the specified directory and its subdirectories-V displays detailed processing information-deference acts on the pointing of symbolic links, Instead of the link file itself, select parameters:--reference=<directory or file>Use the specified directory/file as a reference and set the operating file/directory to the same owner and group as the reference file/directory--from=<Current User: Current group> Changes are made only if the current user and group are the same as the specified user and group--help display Help information--version display version information 4. Use instance: Instance 1: Change owner and Group command: chown mail:mail log2012.log output: Copy code [[email protected] test6]# ll---xr--r--1 root user  s 302108 11-30 08:39 linklog.log---xr--r--1 root users 302108 11-30 08:39 log2012.log-rw-r--r--1 root users 61 11-30 08:39 log2013.log-rw-r--r--1 root users 0 11-30 08:39 log2014.log-rw-r--r--1 root users 0 11-30 08:39 log2015 . log-rw-r--r--1 Root users 0 11-30 08:39 log2016.log-rw-r--r--1 root users 0 11-30 08:39 LOG2017.LOG[[EMAIL&NB Sp;protected] test6]# chown mail:mail log2012.log [[email protected] test6]# ll---xr--r--1 root users 302108 11-30 0 8:39 linklog.log---xr--r--1 mail mail 302108 11-30 08:39 log2012.log-rw-r--r--1 root users, 11-30 08:39 LOG2013.L  og-rw-r--r--1 root users 0 11-30 08:39 log2014.log-rw-r--r--1 root users 0 11-30 08:39 log2015.log-rw-r--r--1 Root users 0 11-30 08:39 log2016.log-rw-r--r--1 root users 0 11-30 08:39 log2017.log[[email protected] Test6] #复制代码 Description: Example 2: Change file owner and group commands: chown root:log2012.log output: Copy code [[E Mail protected] test6]# ll Total 604---xr--r--1 root users 302108 11-30 08:39 linklog.log---xr--r--1 mail mail 302108 11-30 08:39 log2012.log-rw-r--r--1 root users 11-30 08:39 log2013.log-rw-r--r--1 root users 0 11-30 08:39 Lo g2014.log-rw-r--r--1 root users 0 11-30 08:39 log2015.log-rw-r--r--1 root users 0 11-30 08:39 log2016.log-rw-r --r--1 root users 0 11-30 08:39 log2017.log[[email protected] test6]# chown root:log2012.log [[Email prot Ected] test6]# ll Total 604---xr--r--1 root users 302108 11-30 08:39 linklog.log---xr--r--1 root root 302108 11-30 08:39 lo g2012.log-rw-r--r--1 root users 11-30 08:39 log2013.log-rw-r--r--1 root users 0 11-30 08:39 log2014.log-rw-r --r--1 root users 0 11-30 08:39 log2015.log-rw-r--r--1 root users 0 11-30 08:39 log2016.log-rw-r--r--1 root u Sers 0 11-30 08:39Log2017.log[[email protected] Test6] #复制代码 Description: Instance 3: Change file Group command: Chown:mail log2012.log output: Copy code [[Email pro Tected] test6]# ll Total 604---xr--r--1 root users 302108 11-30 08:39 linklog.log---xr--r--1 root root 302108 11-30 08:39 l og2012.log-rw-r--r--1 root users 11-30 08:39 log2013.log-rw-r--r--1 root users 0 11-30 08:39 log2014.log-rw- r--r--1 root users 0 11-30 08:39 log2015.log-rw-r--r--1 root users 0 11-30 08:39 log2016.log-rw-r--r--1 root Users 0 11-30 08:39 log2017.log[[email protected] test6]# chown:mail log2012.log [[email protected] test6] # LL Total 604---xr--r--1 root users 302108 11-30 08:39 linklog.log---xr--r--1 root mail 302108 11-30 08:39 log2012.log-rw- r--r--1 root users 11-30 08:39 log2013.log-rw-r--r--1 root users 0 11-30 08:39 log2014.log-rw-r--r--1 root Users 0 11-30 08:39 log2015.log-rw-r--r--1 root users 0 11-30 08:39 log2016.log-rw-r--r--1 root users 0 1 1-30 08:39 log2017.log CopyCode Description: Instance 4: Change owner and group commands for all files in the specified directory and its subdirectories: chown-r-v root:mail test6 output: Copy code [[email protected] test]# LLDRW  Xr-xr-x 2 root users 4096 11-30 08:39 test6[[email protected] test]# chown-r-v root:mail test6 "Test6/log2014.log" The owner has changed to Root:mail the owner of "Test6/linklog.log" has changed to root:mail the owner of "Test6/log2015.log" has changed to Root:mail "Test6/log2013.log" The owner has changed to Root:mail the owner of "Test6/log2012.log" has been reserved for Root:mail "Test6/log2017.log" the owner has changed to Root:mail "Test6/log2016.log" The owner has changed to Root:mail the owner of "Test6" has changed to root:mail[[email protected] test]# lldrwxr-xr-x 2 root mail 4096 11-30 08:39 tes  T6[[email protected] test]# CD test6[[email protected] test6]# ll Total 604---xr--r--1 root mail 302108 11-30 08:39 Linklog.log---xr--r--1 root mail 302108 11-30 08:39 log2012.log-rw-r--r--1 root mail, 11-30 08:39 log2013.log-rw- r--r--1 root mail 0 11-30 08:39 log2014.log-rw-r--r--1 root mail 0 11-30 08:39 log2015.log-rw-r--r--1 root ma Il 0 11-30 08:39 log2016.log-rw-r--r--1 root mail 0 11-30 08:39 log2017.log 

Chown 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.