chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID;组可以是组名或者组ID;文件是以空格分开的要改变权限的文件列表,支持通配符。系统管理员经常使用chown命令,在将文件拷贝到另一个用户的名录下之后,让用户拥有使用该文件的权限。

  只有文件主和超级用户才可以便用该命令。

语法

  chown(选项)(参数)

选项

-c或——changes:效果类似“-v”参数,但仅回报更改的部分;

-f或--quite或——silent:不显示错误信息;

-h或--no-dereference:只对符号连接的文件作修改,而不更改其他任何相关文件;

-R或——recursive:递归处理,将指定目录下的所有文件及子目录一并处理;

-v或——version:显示指令执行过程;

--dereference:效果和“-h”参数相同;

--help:在线帮助;

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

--version:显示版本信息。

参数

用户:组:指定所有者和所属工作组。当省略“:组”,仅改变文件所有者;

文件:指定要改变所有者和工作组的文件列表。支持多个文件和目标,支持shell通配符。

常用示例

1、新增用户以及用户组

[root@CTU1000094641 ~]# groupadd test    #新增用户组test          
[root@CTU1000094641 ~]# useradd -m -g test temptest  #新增用户组test下的用户temptest
[root@CTU1000094641 ~]# passwd temptest    #给用户temptest设置密码,然后就可以使用了
Changing password for user temptest.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

2.修改文件的用户以及用户组

  命令:chown  用户:用户组  文件   

[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. root root Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. root root Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx
[root@CTU1000094641 test]# chown temptest:test test1.xlsx
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. root root Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx

  如果用户是唯一的标识,那么也可以用:chown  用户:  文件

drwxr-xr-x.  devdeploy root   Dec   : testsub
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. root root Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx
[root@CTU1000094641 test]# chown temptest: test3.xlsx
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. temptest test Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx

3、修改文件的用户为当前用户组下的用户(即使当前用户组没有该用户) 

  命令:chown  用户  文件    

[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. root root Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. root root Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx
[root@CTU1000094641 test]# chown temptest test1.xlsx     #事实上root用户组并没有temptest用户
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest root Dec : test1.xlsx
-rw-r--r--. root root Dec : test2.xlsx
-rw-r--r--. root root Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx

4、修改文件所属的用户组

[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. temptest test Dec : test2.xlsx
-rw-r--r--. temptest test Dec : test3.xlsx
-rw-r--r--. root root Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx
[root@CTU1000094641 test]# chown :test test4.xlsx
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. temptest test Dec : test2.xlsx
-rw-r--r--. temptest test Dec : test3.xlsx
-rw-r--r--. root test Dec : test4.xlsx
drwxr-xr-x. devdeploy root Dec : testsub ./testsub:
total
-rw-r--r--. devdeploy root Dec : test5.xlsx

5、修改目录及其下面的所有文件、子目录的文件主

  命令:chown -R  -v  拥有者:群组 文件目录(除了-R外与单文件修改没啥不同)

[root@CTU1000094641 attachment]# chown -R -v temptest:test ./test
changed ownership of `./test/test4.xlsx' to temptest:test
ownership of `./test/test1.xlsx' retained as temptest:test
ownership of `./test/test2.xlsx' retained as temptest:test
changed ownership of `./test/testsub/test5.xlsx' to temptest:test
changed ownership of `./test/testsub' to temptest:test
ownership of `./test/test3.xlsx' retained as temptest:test
changed ownership of `./test' to temptest:test
[root@CTU1000094641 attachment]# cd test
[root@CTU1000094641 test]# ll -lR
.:
total
-rw-r--r--. temptest test Dec : test1.xlsx
-rw-r--r--. temptest test Dec : test2.xlsx
-rw-r--r--. temptest test Dec : test3.xlsx
-rw-r--r--. temptest test Dec : test4.xlsx
drwxr-xr-x. temptest test Dec : testsub ./testsub:
total
-rw-r--r--. temptest test Dec : test5.xlsx

linux命令学习之:chown的更多相关文章

  1. 别出心裁的Linux命令学习法

    别出心裁的Linux命令学习法 操作系统操作系统为你完成所有"硬件相关.应用无关"的工作,以给你方便.效率.安全.操作系统的功能我总结为两点:管家婆和服务生: 管家婆:通过进程.虚 ...

  2. linux命令学习之:chmod

    chmod命令用来变更文件或目录的权限.在Linux系统家族里,文件或目录权限的控制分别以读取R.写入W.执行X3种一般权限来区分,另有3种特殊权限可供运用.用户可以使用chmod指令去变更文件与目录 ...

  3. 《Linux命令学习手册》系列分享专栏

    <Linux命令学习手册>系列分享专栏 <Linux命令学习手册>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/207 ...

  4. 20155229付钰涵-虚拟机安装及LINUX命令学习

    安装Ubuntu遇到的问题 问题一: 新建虚拟电脑的版本只有32-bit,与老师所给教程中的64-bit不符.为此我上百度搜寻了答案. 第一种方法: 控制面板--程序与功能--启动或关闭windows ...

  5. Linux命令学习笔记目录

    Linux命令学习笔记目录 最近正在使用,linux,顺便将用到的命令整理了一下. 一. 文件目录操作命令: 0.linux命令学习笔记(0):man 命令 1.linux命令学习笔记(1):ls命令 ...

  6. 常见Linux命令学习

    Linux命令学习 命令分类: 文件处理命令 权限管理命令 文件搜索命令 帮助命令 用户管理命令 压缩解压命令 网络命令 关机重启命令 1.文件处理命令 命令格式:命令 [-选项] [参数] 例:ls ...

  7. Linux命令学习

    Linux命令学习 Ubuntu常用快捷键 •Ctrl+Alt+T: 打开终端 •Ctrl+Shift+T: 新建标签页 •Tab: 终端中命令补全 •Alt+数字N: 终端中切换到第N个标签页 •↑ ...

  8. Linux命令学习总结之rmdir命令的相关资料可以参考下

    这篇文章主要介绍了Linux命令学习总结之rmdir命令的相关资料,需要的朋友可以参考下(http://www.nanke0834.com) 命令简介: rmdir命令用用来删除空目录,如果目录非空, ...

  9. Linux命令学习笔记1

    1.Linux命令学习 2.Mkdir /data       -创建文件夹 在/下创建文件夹 data 3.Cd               -目录切换 列如cd / 4.Touch /data/1 ...

  10. 安装虚拟机&Linux命令学习

    安装虚拟机&Linux命令学习 基于VirtualBox虚拟机安装Ubuntu 1.下载安装VirtualBox 根据自己电脑(32位操作系统)的实际情况,我在网上找了相应的VirtualBo ...

随机推荐

  1. cxgrid中回车键光标移到下列

    OptionsBehavior.GoToNextCellOnEnter:=True; 更完善的回车 可以在焦点到了最后一列再回车时有下一行则移到下一行的第一列,没有下一行则新增记录并移到第一列 pro ...

  2. java后端实习生面试题目

    1.编程题:java从10000到99999找到AABB类型 public class Test1 { public static void main(String[] args) { String ...

  3. Python中fileinput模块使用方法

    fileinput模块提供处理一个或多个文本文件的功能,可以通过使用for循环来读取一个或多个文本文件的所有行.python2.7文档关于fileinput介绍:fileinput   fileinp ...

  4. ServiceWorker和WebWorker

    在google打上关键字 service worker 空格进行搜索 参考地址 (Web_worker)[https://en.wikipedia.org/wiki/Web_worker] (serv ...

  5. Delphi 透明窗体显示文字

    设置窗体属性:BorderStyle 属性设置为 bsNoneColor 属性设置为 clWhite(白色:窗体背景色)TransparentColor 属性设置为 trueTransparentCo ...

  6. 关于 私有变量的访问问题【 java python]

    #coding:utf-8 class Teacher(): __clas = '' # 类私有变量同样遵循,只能在类内部访问,外部无法访问,但是类的方法可以访问同类所有对象私有变量这个规则. def ...

  7. ArcGIS案例学习笔记-批处理擦除挖空挖除相减

    ArcGIS案例学习笔记-批处理擦除挖空挖除相减 联系方式:谢老师,135-4855-4328,xiexiaokui#qq.com 目的:批处理擦除.挖空.挖除.相减 数据源:chp13/ex5/pa ...

  8. Swift自定义UINavigationController(背景颜色、背景图片、返回按钮设置、字体大小等)

    1.0  自定义UINavigationController时,背景图片.颜色等只需要设置一次,所以我们可以重写  initializa  这个方法来实现我们想要的效果 override  class ...

  9. spring boot 项目配置字符编码

  10. 关于 uboot 的异常向量表

    ldr r,address 表示将 address 地址中的内容存入 r0 中