Common Linux commands (24)-chown
Chown changes the owner of a specified file to a specified user or group. The user can be the user name or user ID, and the group can be the group name or group ID; files are separated by spaces to change the permission list. Wildcards are supported. The system administrator often uses the chown command to grant the user the permission to use the file after copying the file to another user's directory.
1. Command Format:
Chown [Option]... [owner] [: [group] file...
2. command functions:
Use chown to change the owner and group of a file. When changing the file owner or group, you can use the user name and user ID settings. Normal users cannot change their files to other owners. The operation permission is generally administrator.
3. command parameters:
Required parameters:
-C: display the changed information.
-F ignore error messages
-H: fixed the symbolic link.
-R processes the specified directory and all files in its subdirectories.
-V: displays detailed processing information.
-Deference acts on the point of the symbolic link, rather than the link file itself.
Select parameters:
-- Reference = <directory or File> specifies the directory/file as a reference, and sets the operated file/directory to the same owner and group of the reference file/directory.
-- From = <Current User: current group> only when the current user and group are the same as the specified user and group
-- Help: displays help information.
-- Version: displays version information.
4. Command instance:
Instance 1.Change owner and group
Command: chown mail: mail log2012.log
[root@localhost test6]# ll---xr--r-- 1 root users 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[root@localhost test6]# chown mail:mail log2012.log [root@localhost test6]# ll---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 61 11-30 08:39 log2013.log[root@localhost test6]#
Instance 2. Change the file owner and group
Command: chown root: log2012.log
[root@localhost test6]# ll---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 61 11-30 08:39 log2013.log[root@localhost test6]# chown root: log2012.log [root@localhost test6]# ll---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root root 302108 11-30 08:39 log2012.log-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log[root@localhost test6]#
Instance 3. Change the file group
Command: chown: mail log2012.log
[root@localhost test6]# ll---xr--r-- 1 root users 302108 11-30 08:39 linklog.log---xr--r-- 1 root root 302108 11-30 08:39 log2012.log-rw-r--r-- 1 root users 61 11-30 08:39 log2013.log[root@localhost test6]# chown :mail log2012.log [root@localhost test6]# ll---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 61 11-30 08:39 log2013.log
Instance 4. Change the owner and group of all files in the specified directory and Its subdirectories
Command: chown-R-v root: mail test6
[Root @ localhost test] # lldrwxr-xr-x 2 root users 4096 11-30 test6 [root @ localhost test] # chown-R-v root: the owner of mail test6 "test6/log2014.log" has been changed to root: mail "test6/linklog. the owner of log has been changed to root: mail "test6/log2015.log" and changed to root: mail "test6: mail [root @ localhost test] # lldrwxr-xr-x 2 root mail 4096 11-30 test6 [root @ localhost test] # cd test6 [root @ localhost test6] # ll --- xr -- r -- 1 root mail 302108 11-30 linklog. log --- xr -- r -- 1 root mail 302108 11-30 log2012.log-rw-r -- 1 root mail 61 11-30 log2013.log
Original article: http://www.cnblogs.com/peida