1.释义
将目录或文件的拥有者、拥有组改为指定的用户或组
2.系统帮助
用法:chown [选项]... [所有者][:[组]] 文件...
或:chown [选项]... --reference=参考文件 文件...
Change the owner and/or group of each FILE to OWNER and/or GROUP.
With --reference, change the owner and group of each FILE to those of RFILE.
-c, --changes like verbose but report only when a change is made
-f, --silent, --quiet suppress most error messages
-v, --verbose output a diagnostic for every file processed
--dereference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h, --no-dereference affect symbolic links instead of any referenced file
(useful only on systems that can change the
ownership of a symlink)
--from=当前所有者:当前所属组
只当每个文件的所有者和组符合选项所指定时才更改所
有者和组。其中一个可以省略,这时已省略的属性就不
需要符合原有的属性。
--no-preserve-root do not treat '/' specially (the default)
--preserve-root fail to operate recursively on '/'
--reference=RFILE use RFILE's owner and group rather than
specifying OWNER:GROUP values
-R, --recursive 权限递归
The following options modify how a hierarchy is traversed when the -R
option is also specified. If more than one is specified, only the final
one takes effect.
-H if a command line argument is a symbolic link
to a directory, traverse it
-L traverse every symbolic link to a directory
encountered
-P do not traverse any symbolic links (default)
--help显示此帮助信息并退出
--version显示版本信息并退出
Owner is unchanged if missing. Group is unchanged if missing, but changed
to login group if implied by a ':' following a symbolic OWNER.
OWNER and GROUP may be numeric as well as symbolic.
示例:
chown root /u将 /u 的属主更改为"root"。
chown root:staff /u和上面类似,但同时也将其属组更改为"staff"。
chown -hR root /u将 /u 及其子目录下所有文件的属主更改为"root"。
GNU coreutils online help:
请向 报告chown 的翻译错误
要获取完整文档,请运行:info coreutils 'chown invocation'
3.示例
3.1.更改拥有者
[root@itbkz s]#mkdir mulu
[root@itbkz s]#touch mulu/test.txt
[root@itbkz s]#ll -d mulu
drwxr-xr-x 2 root root 22 12月 5 17:00 mulu
[root@itbkz s]#ll mulu/test.txt
-rw-r--r-- 1 root root 0 12月 5 17:00 mulu/test.txt
[root@itbkz s]#ll
总用量 0
drwxr-xr-x 2 root root 22 12月 5 17:00 mulu
[root@itbkz s]#chown itbkz mulu
[root@itbkz s]#ll
总用量 0
drwxr-xr-x 2 itbkz root 22 12月 5 17:00 mulu
3.2.更改拥有组
[root@itbkz s]#chown .itbkz mulu
[root@itbkz s]#ll
总用量 0
drwxr-xr-x 2 root itbkz 22 12月 5 17:00 mulu
3.3.更改拥有者和组
[root@itbkz s]#chown itbkz:itbkz mulu
[root@itbkz s]#ll
总用量 0
drwxr-xr-x 2 itbkz itbkz 22 12月 5 17:00 mulu
3.4.拥有用户及组权限递归
方法1:
[root@itbkz s]#chown -R itbkz:itbkz mulu
[root@itbkz s]#ll -d mulu
drwxr-xr-x 2 itbkz itbkz 22 12月 5 17:00 mulu
[root@itbkz s]#ll mulu/test.txt
-rw-r--r-- 1 itbkz itbkz 0 12月 5 17:00 mulu/test.txt
方法2:
[root@itbkz s]#chown -R itbkz.itbkz mulu
[root@itbkz s]#ll -d mulu
drwxr-xr-x 2 itbkz itbkz 22 12月 5 17:00 mulu
[root@itbkz s]#ll mulu/test.txt
-rw-r--r-- 1 itbkz itbkz 0 12月 5 17:00 mulu/test.txt
IT博客站版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:chown命令将目录或文件的拥有者、拥有组改为指定的用户或组