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. git 每次push都需要输入用户和密码

    git remote -v origin https://github.com/userName/xx.git (fetch) origin https://github.com/userName/x ...

  2. 【358】GitHub 上面文件夹下载方法

    参考:https://www.bilibili.com/read/cv210500/ 参考:https://www.jianshu.com/p/743ecc20ffb2 软件下载:Downloads ...

  3. Linux 多进程实现方法

    1.需求 查找192.168.0.*网段中所有未使用过的IP 2.实现     我们知道查找未使用IP的方法可以使用ping命令完成.对于单个IP的判断,使用命令如下 $ 192.168.0.1 PI ...

  4. echarts.js制作中国地图

    一.准备 1.  打开sublime,新建一个echarts文件夹,新建echarts.html文件 2.  在echarts.html文件中,为ECharts准备一个Dom(id是china-map ...

  5. [重点]delphi 实现 根据给定的标题去《中国青年报》网上电子报数据中查找匹配的内容,并从该内容中取出引题、正题、副题、作者和正文。

    项目要求:根据给定的标题去<中国青年报>网上电子报数据中查找匹配的内容,并从该内容中取出引题.正题.作者和正文. unit Unit1; interface uses Winapi.Win ...

  6. Running Your Application

    在运行你的第一个app前,您先要了解以下文件: 1.AndroidManifest.xml:Android的基本配置信息: <uses-sdk> element:app兼容版本信息: ex ...

  7. 吴裕雄 python深度学习与实践(1)

    #coding = utf8 import threading,time count = 0 class MyThread(threading.Thread): def __init__(self,t ...

  8. Python中struct.pack()和struct.unpack()

    https://blog.csdn.net/tjuyanming/article/details/79700601 https://www.cnblogs.com/yezl/p/5861787.htm ...

  9. springboot-day01-引入基础

    1. 今日大纲 1. 了解Spring的发展 2. 掌握Spring的java配置方式 3. 学习Spring Boot 4. 使用Spring Boot完成CRUD 2. Spring的发展 2.1 ...

  10. Android Studio SVN配置

    一 . 原文链接:忽略文件[转]    https://blog.csdn.net/buaaroid/article/details/51546521 1.用Android Studio创建一个项目, ...