chown命令改变某个文件或目录的所有者和所属的组,该命令可以向某个用户授权,使该用户变成指定文件的所有者或者改变文件所属的组。

    (1)用法:

    用法:  chown [选项]... [所有者][:[组]] 文件...

或   chown [选项]... --reference=参考文件 文件...

    (2)功能:

功能:  更改每个文件的所有者和/或所属组。

当使用 --referebce 参数时,将文件的所有者和所属组更改为与指定参考文件相同。

用户可以是用户或者是用户D,用户组可以是组名或组id。文件名可以使由空格分开的文件列表,在文件名中可以包含通配符。

    (3)选项参数:

1) -R --recursive            递归处理,将指定目录下的所有文件及子目录一并处理

2) -f                   忽略错误信息

3) -v                    显示详细的处理信息

4) -c                    显示更改的部分的信息

5) --reference=<参考文件或目录>    把指定文件或目录的拥有者与所属群组全部设成和参考文件或目录的拥有者与所属群组相同

    (4)实例:

1)[root@localhost Documents]# chown -v sunjimeng findDir/Dir/{head_text,less1,less2}        改变文件的拥有者(指名多个文件时还可以用空格隔开)

  1. [root@localhost Documents]# ls -l findDir/Dir
  2. 总用量
  3. -r-xr-xr-x. root root 5 : head_text
  4. -r-xr-xr-x. root root 5 : less1
  5. -r-xr-xr-x. root root 5 : less2
  6. [root@localhost Documents]# chown -v sunjimeng findDir/Dir/{head_text,less1,less2} 在指明路径时,findDir在当前目录Documents下,所以不能带/。
  7. changed ownership of "findDir/Dir/head_text" from root to sunjimeng
  8. changed ownership of "findDir/Dir/less1" from root to sunjimeng
  9. changed ownership of "findDir/Dir/less2" from root to sunjimeng
  10. [root@localhost Documents]# ls -l findDir/Dir
  11. 总用量
  12. -r-xr-xr-x. sunjimeng root 5 : head_text
  13. -r-xr-xr-x. sunjimeng root 5 : less1
  14. -r-xr-xr-x. sunjimeng root 5 : less2

2)[root@localhost Documents]# chown -vR sunjimeng findDir/Dir          递归地将文件夹下的所有文件的所属组改变

  1. [root@localhost Documents]# ls -l findDir/Dir
  2. 总用量
  3. -r-xr-xr-x. sunjimeng root 5 : head_text
  4. -r-xr-xr-x. sunjimeng root 5 : less1
  5. -r-xr-xr-x. sunjimeng root 5 : less2
  6. [root@localhost Documents]# ls -l findDir
  7. 总用量
  8. dr-xr-xr-x. root root 5 : Dir //在实例1中并没有改变文件夹的所有者
  9. [root@localhost Documents]# chown -v root findDir/Dir/{head_text,less1,less2} //先把所有者复原为root
  10. changed ownership of "findDir/Dir/head_text" from sunjimeng to root
  11. changed ownership of "findDir/Dir/less1" from sunjimeng to root
  12. changed ownership of "findDir/Dir/less2" from sunjimeng to root
  13. [root@localhost Documents]# chown -vR sunjimeng findDir/Dir //再递归地把Dir文件夹和其下的文件所有者更改
  14. changed ownership of "findDir/Dir/head_text" from root to sunjimeng
  15. changed ownership of "findDir/Dir/less2" from root to sunjimeng
  16. changed ownership of "findDir/Dir/less1" from root to sunjimeng
  17. changed ownership of "findDir/Dir" from root to sunjimeng
  18. [root@localhost Documents]# ls -l findDir              //在这里查看,文件夹Dir及其下文件的所有者都已经改变为sunjimeng
  19. 总用量
  20. dr-xr-xr-x. sunjimeng root 5 : Dir
  21. [root@localhost Documents]# ls -l findDir/Dir
  22. 总用量
  23. -r-xr-xr-x. sunjimeng root 5 : head_text
  24. -r-xr-xr-x. sunjimeng root 5 : less1
  25. -r-xr-xr-x. sunjimeng root 5 : less2

3[root@localhost Documents]# chown -vR root:sunjimeng findDir              改变所有者的同时改变所属组

  1. [root@localhost Documents]# chown -vR root:sunjimeng findDir
  2. changed ownership of "findDir/Dir/head_text" from sunjimeng:root to root:sunjimeng
  3. changed ownership of "findDir/Dir/less2" from sunjimeng:root to root:sunjimeng
  4. changed ownership of "findDir/Dir/less1" from sunjimeng:root to root:sunjimeng
  5. changed ownership of "findDir/Dir" from sunjimeng:root to root:sunjimeng
  6. changed ownership of "findDir" from root:root to root:sunjimeng
  7. [root@localhost Documents]# ll findDir
  8. 总用量
  9. dr-xr-xr-x. root sunjimeng 5 : Dir
  10. [root@localhost Documents]# ll findDir/Dir
  11. 总用量
  12. -r-xr-xr-x. root sunjimeng 5 : head_text
  13. -r-xr-xr-x. root sunjimeng 5 : less1
  14. -r-xr-xr-x. root sunjimeng 5 : less2

4)[root@localhost Dir]# chown -c .root head_text less1                 只改变文件的所属组(-c参数与-v类似)

  1. [root@localhost Dir]# ll
  2. 总用量
  3. -r-xr-xr-x. root sunjimeng 5 : head_text
  4. -r-xr-xr-x. root sunjimeng 5 : less1
  5. -r-xr-xr-x. root sunjimeng 5 : less2
  6. [root@localhost Dir]# chown -c .root head_text less1
  7. changed ownership of "head_text" from root:sunjimeng to :root
  8. changed ownership of "less1" from root:sunjimeng to :root
  9. [root@localhost Dir]# chgrp -v root head_text less2
  10. "head_text" 的所属组已保留为root //因为文件的所属组已经为root了,所以这里显示保留为root
  11. changed group of "less2" from sunjimeng to root
  12. [root@localhost Dir]# ll
  13. 总用量
  14. -r-xr-xr-x. root root 5 : head_text
  15. -r-xr-xr-x. root root 5 : less1
  16. -r-xr-xr-x. root root 5 : less2

5)[root@localhost Dir]# chown -v :sunjimeng less1  和[root@localhost Dir]# chown -v :sunjimeng less1 和[root@localhost Dir]# chown -v sunjimeng head_text

  1. [root@localhost Dir]# ll
  2. 总用量
  3. -r-xr-xr-x. root root 5 : head_text
  4. -r-xr-xr-x. root root 5 : less1
  5. -r-xr-xr-x. root root 5 : less2
  6. [root@localhost Dir]# chown -v :sunjimeng less1
  7. changed ownership of "less1" from root:root to :sunjimeng
  8. [root@localhost Dir]# chown -v .sunjimeng less2
  9. changed ownership of "less2" from root:root to :sunjimeng
  10. [root@localhost Dir]# chown -v sunjimeng head_text
  11. changed ownership of "head_text" from root to sunjimeng
  12. [root@localhost Dir]# ll
  13. 总用量
  14. -r-xr-xr-x. sunjimeng root 5 : head_text
  15. -r-xr-xr-x. root sunjimeng 5 : less1
  16. -r-xr-xr-x. root sunjimeng 5 : less2

    (5)其他:

在更改文件的所有者或所属群组时,可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。

以下选项是在指定了 -R 选项时被用于设置如何穿越目录结构体系。 如果您指定了多于一个选项,那么只有最后一个会生效。

  -H 如果命令行参数是一个通到目录的符号链接,则遍历符号链接 -L 遍历每一个遇到的通到目录的符号链接

  -P 不遍历任何符号链接(默认)

  --help 显示此帮助信息并退出

  --version 显示版本信息并退出 如果没有指定所有者,则不会更改。

  所属组若没有指定也不会更改,但当加上 ":"时 GROUP 会更改为指定所有者的主要组。所有者和所属组可以是数字或名称。

每天一个Linux命令(26)chown命令的更多相关文章

  1. 详解Linux chgrp和chown命令的用法

    Linux chgrp和chown命令是管理员的常用命令,对于初学Linux系统管理的人来说,这对Linux chgrp和chown命令具体的用法这里做一介绍. Linux chgrp命令 功能:改变 ...

  2. 每天一个linux命令31)--chown命令

    chown将 指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID,组可以使组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷 ...

  3. linux命令之chown命令

    发布:JB01   来源:脚本学堂     [大 中 小] 本文介绍下,linux系统中用于文件与目录权限管理的命令 chown命令的用法,chown将指定文件的拥有者改为指定的用户或组.有需要的朋友 ...

  4. linux的chmod,chown命令详解

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...

  5. linux的chmod,chown命令 详解

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...

  6. linux常用命令:chown 命令

    chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...

  7. linux命令之------Chown命令

    Chown命令 1) 作用:将指定文件的拥有者改为指定的用户或组. 2) -c:显示更改的部分的信息. 3)-f:忽略错误信息. 4)-h:修复符号链接. 5)-v:显示详细的处理信息. 6)-R:处 ...

  8. linux chmod命令和chown命令

    一.chmod及文件权限 1.了解文件权限 root账户新建一个目录permission,在该目录新建一个文件file,通过ll就可以查看其权限. root@development:~# cd per ...

  9. 【转载】每天一个Linux命令

    目  录 每天一个linux命令(1)  : ls 命令 每天一个linux命令(2)  : cd 命令 每天一个linux命令(3)  : pwd 命令 每天一个linux命令(4)  : mkdi ...

  10. Linux自学之旅-基础命令(chown和chgrp)

    转: Linux自学之旅-基础命令(chown和chgrp) Linux自学之旅-基础命令(改变所有者与所属组的命令) 文章目录 前言 一.chown命令 二.chgrp命令 总结 前言 1.上一节我 ...

随机推荐

  1. Oracle 查询用户表信息,导入导出处理表空间不一致

    select table_name,tablespace_name from user_tables t; //查询用户默认表空间信息 SELECT t.* FROM USER_USERS t; 导入 ...

  2. NoSQL之Redis学习小结

    大数据时代要求: 三V:Volume海量.Velocity实时.Variety多样: 三高:高并发.高可扩.高性能 高并发操作不建议使用关联查询,而使用冗余数据,分布式系统支持不了太多的并发. 横向 ...

  3. [linux]netstat命令详解-显示linux中各种网络相关信息

    1.功能与说明 netstat 用于显示linux中各种网络相关信息.如网络链接 路由表  接口状态链接 多播成员等等. 2.参数含义介绍 -a (all)显示所有选项,默认不显示LISTEN相关-t ...

  4. Windows2008RC2 IIS配置php执行环境

    1:下载一个php manager,安装.打开IIS管理器后,点击计算机,就能够看到右边PHPManager 静静地躺在那儿了.双击PHPManager    后我们就能够開始对PHP进行配置了. 2 ...

  5. Atitit. 如何判断软件工程师 能力模型 程序员能力模型  项目经理能力模型

    Atitit. 如何判断软件工程师 能力模型 程序员能力模型  项目经理能力模型 这里能力模型的标准化是对工具的使用为基本 工具(ide,语言,类库,框架,软件) 第一步 ::可使用api 类库 框架 ...

  6. 写sql语句统计各个学生各科成绩(case when用法)

    尊重原创:http://blog.csdn.net/love_java_cc/article/details/78268326 有如下一张表score: 建表语句: CREATE TABLE `sco ...

  7. hdu 1811 Rank of Tetris(拓扑,并查集)

    题意:略 分析:排序先按rating,若相同,则按rp.考虑到每个人的rp均不同,所以rating相同的人必然可以排序.那么只需要考虑rating不同的集合了.  大小关系可以用有向边表示,而大小关系 ...

  8. 基于java spring框架开发部标1078视频监控平台精华文章索引

    部标1078视频监控平台,是一个庞杂的工程,涵盖了多层协议,部标jt808,jt809,jt1078,苏标Adas协议等,多个平台功能标准,部标796标准,部标1077标准和苏标主动安全标准,视频方面 ...

  9. erlang 爬虫——爬取网页图片

    说起爬虫,大家第一印象就是想到了python来做爬虫.其实,服务端语言好些都可以来实现这个东东. 在我们日常上网浏览网页的时候,经常会看到一些好看的图片,我们就希望把这些图片保存下载,或者用户用来做桌 ...

  10. XtraBackup全备与增量备份

    一.XtraBackup安装 下载地址:http://www.percona.com/downloads/XtraBackup/XtraBackup-2.2.8/source/ 安装步骤: ===== ...