【Linux】一步一步学Linux——chown命令(112)
2019-08-06 21:54
1561 查看
版权声明:署名,允许他人基于本文进行创作,且必须基于与原先许可协议相同的许可协议分发本文 (Creative Commons)
00. 目录
文章目录
01. 命令概述
chown - 修改文件所有者和所属组
Linux/Unix 属于多用户多任务操作系统,所有的文件皆有拥有者。利用 chown 命令可以将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID,组可以是组名或者组ID,文件是以空格分开的要改变权限的文件列表,支持通配符。 一般来说,这个指令仅限系统管理者(root)所使用,普通用户没有权限改变文件所属者及所属组。
02. 命令格式
用法:chown [选项]... [所有者][:[组]] 文件... 或:chown [选项]... --reference=参考文件 文件...
03. 常用选项
当使用 --referebce 参数时,将文件的所有者和所属组更改为与指定参考文件相同。 -c, --changes 类似 verbose,但只在有更改时才显示结果 --dereference 受影响的是符号链接所指示的对象,而非符号链接本身 -h, --no-dereference 会影响符号链接本身,而非符号链接所指示的目的地 (当系统支持更改符号链接的所有者时,此选项才有用) --from=当前所有者:当前所属组 只当每个文件的所有者和组符合选项所指定时才更改所 有者和组。其中一个可以省略,这时已省略的属性就不 需要符合原有的属性。 --no-preserve-root 不特殊对待"/"(默认值) --preserve-root 不允许在"/"上递归操作 -f, --silent, --quiet 去除大部份的错误信息 --reference=参考文件 使用参考文件的所属组,而非指定值 -R, --recursive 递归处理所有的文件及子目录 -v, --verbose 为处理的所有文件显示诊断信息 --help 显示此帮助信息并退出 --version 显示版本信息并退出
04. 参考示例
4.1 修改文件所属者和所属组为tom
[root@itcast test]# ls -l file -rwxr-x--x 1 deng deng 0 8月 6 20:06 file [root@itcast test]# chown tom:tom file [root@itcast test]# ls -l file -rwxr-x--x 1 tom tom 0 8月 6 20:06 file [root@itcast test]#
4.2 修改文件所属者为deng用户
[root@itcast test]# chown deng file [root@itcast test]# ls - 7ff7 l file -rwxr-x--x 1 deng tom 0 8月 6 20:06 file [root@itcast test]#
4.3 修改文件所属者为deng用户和所属组为itcast组
[root@itcast test]# chown deng:itcast file [root@itcast test]# ls -l file -rwxr-x--x 1 deng itcast 0 8月 6 20:06 file [root@itcast test]#
4.4 修改文件所属组为tom组
[root@itcast test]# chown :tom file [root@itcast test]# ls -l file -rwxr-x--x 1 deng tom 0 8月 6 20:06 file [root@itcast test]#
4.5 递归修改所有的文件及子目录所属者和所属组
[root@itcast test]# chown -R deng:deng test/
4.6 显示修改动作
[root@itcast test]# chown -c root:root file changed ownership of "file" from deng:tom to root:root [root@itcast test]#
或者
[root@itcast test]# chown -v deng:deng file changed ownership of "file" from root:root to deng:deng [root@itcast test]#
4.7 修改文件所属者和所属组
[root@itcast test]# chown 1002:1003 file [root@itcast test]# ls -l file -rwxr-x--x 1 itcast itcast 0 8月 6 20:06 file [root@itcast test]#
注意:1002和1003必须是存在的用户和用户组。
4.8 修改文件所属组
[root@itcast test]# chown .deng file [root@itcast test]# ls -l file -rwxr-x--x 1 itcast deng 0 8月 6 20:06 file [root@itcast test]#
注意:组用户名deng前面有一个点。
05. 总结
06. 附录
相关文章推荐
- linux命令——chmod/chown
- 每天一个linux命令(30): chown命令
- linux-shell命令之chown(change owner)【更改拥有者】
- Linux 命令-chown
- linux的chmod,chown命令 详解
- 【Linux】一步一步学Linux——cut命令(44)
- 【Linux】一步一步学Linux——du命令(78)
- linux chown命令
- 每天一个linux命令:chown
- linux中chown命令
- Linux基础命令---chown
- linux的chmod,chown命令 详解
- linux常用命令及实例二:cp、mv、chown、chmod、find
- linux命令之 chown
- Linux/Unixchmod,chown命令详解(转)
- 每天一个linux命令(26)--chown
- linux : chgrp/chmod/chown/ln 命令详解
- Linux中文件的可读,可写,可执行权限的解读以及chmod,chown,chgrp命令的用法
- Linux学习21_每天一个linux命令(30): chown命令
- linux下chown命令使用详解--改变档案的所有者