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. 新装kafka与zookeeper配置

    zookeeper配置 dataDir=/opt/kafka_2.11-2.0.0/data/zookeeper # 尽量不要放在tmp# the port at which the clients ...

  2. How to Pronounce Word vs. World

    How to Pronounce Word vs. World Share Tweet Share Tagged With: Comparison, Dark L What is the differ ...

  3. genymotion使用学习

    1 安装 直接去其官网(https://www.genymotion.com/#!/download)下载安装包安装即可,安装中会附带安装VirtualBox. 2 注册 必须使用帐号登录后,方可下载 ...

  4. mysql explain预估剖析

    http://www.cnblogs.com/LBSer/p/3333881.html 引子: 使用MySQL建立了一张表country,总共有才3121行记录. 但是使用explain select ...

  5. 关于那个.get .post .ajax ztree 还有后台servlet传递数据

    servlet给前台传递data串 用的方法是 PrintWriter out = response.getWriter(); // response.sendRedirect("test. ...

  6. C++ 使用VS2010创建MFC ActiveX工程项目

    1.ActiveX的基本概念 ActiveX控件可以看作是一个极小的服务器应用程序,它不能独立运行,必须嵌入到某个容器程序中,与该容器一起运行.这个容器包括WEB网页,应用程序窗体等... Activ ...

  7. php预定义字符

    Php中预定义字符的处理: 1,htmlspecialchars()把一些预定义的字符转换为 HTML 实体. 函数原型:htmlspecialchars(string,quotestyle,char ...

  8. redis 高级特性 不要太好用

    Redis高级特性及应用场景 redis中键的生存时间(expire) redis中可以使用expire命令设置一个键的生存时间,到时间后redis会自动删除它. 过期时间可以设置为秒或者毫秒精度. ...

  9. Rx操作符

    [Rx操作符] 1.Observable.from()方法,它接收一个集合作为输入,然后每次输出一个元素给subscriber: Observable.from("url1", & ...

  10. macaca自动化测试以及配置环境问题

    macaca 测试和环境问题 标签(空格分隔): macaca自动化配置环境问题 macaca环境变量配置 基本环境需要准备的东西: JDK的安装及环境配置:(1.8) Node.js的安装及环境配置 ...