linux命令学习之:chown
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的更多相关文章
- 别出心裁的Linux命令学习法
别出心裁的Linux命令学习法 操作系统操作系统为你完成所有"硬件相关.应用无关"的工作,以给你方便.效率.安全.操作系统的功能我总结为两点:管家婆和服务生: 管家婆:通过进程.虚 ...
- linux命令学习之:chmod
chmod命令用来变更文件或目录的权限.在Linux系统家族里,文件或目录权限的控制分别以读取R.写入W.执行X3种一般权限来区分,另有3种特殊权限可供运用.用户可以使用chmod指令去变更文件与目录 ...
- 《Linux命令学习手册》系列分享专栏
<Linux命令学习手册>系列分享专栏 <Linux命令学习手册>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/207 ...
- 20155229付钰涵-虚拟机安装及LINUX命令学习
安装Ubuntu遇到的问题 问题一: 新建虚拟电脑的版本只有32-bit,与老师所给教程中的64-bit不符.为此我上百度搜寻了答案. 第一种方法: 控制面板--程序与功能--启动或关闭windows ...
- Linux命令学习笔记目录
Linux命令学习笔记目录 最近正在使用,linux,顺便将用到的命令整理了一下. 一. 文件目录操作命令: 0.linux命令学习笔记(0):man 命令 1.linux命令学习笔记(1):ls命令 ...
- 常见Linux命令学习
Linux命令学习 命令分类: 文件处理命令 权限管理命令 文件搜索命令 帮助命令 用户管理命令 压缩解压命令 网络命令 关机重启命令 1.文件处理命令 命令格式:命令 [-选项] [参数] 例:ls ...
- Linux命令学习
Linux命令学习 Ubuntu常用快捷键 •Ctrl+Alt+T: 打开终端 •Ctrl+Shift+T: 新建标签页 •Tab: 终端中命令补全 •Alt+数字N: 终端中切换到第N个标签页 •↑ ...
- Linux命令学习总结之rmdir命令的相关资料可以参考下
这篇文章主要介绍了Linux命令学习总结之rmdir命令的相关资料,需要的朋友可以参考下(http://www.nanke0834.com) 命令简介: rmdir命令用用来删除空目录,如果目录非空, ...
- Linux命令学习笔记1
1.Linux命令学习 2.Mkdir /data -创建文件夹 在/下创建文件夹 data 3.Cd -目录切换 列如cd / 4.Touch /data/1 ...
- 安装虚拟机&Linux命令学习
安装虚拟机&Linux命令学习 基于VirtualBox虚拟机安装Ubuntu 1.下载安装VirtualBox 根据自己电脑(32位操作系统)的实际情况,我在网上找了相应的VirtualBo ...
随机推荐
- input点击后的 默认边框去除
转自 http://blog.sina.com.cn/s/blog_9f1cb4670102v47g.html css文件里加句话:*:focus { outline: none; } 或 input ...
- AWK 知识库
awk 极客课程 <AWK 编程语言>1 <AWK 编程语言>2 <AWK程序设计语言>https://github.com/wuzhouhui/awk http: ...
- git使用 从远程库克隆和更新到本地
从远程库克隆到本地. git clone git@github.com:kingbook/Framework.git 或 git clone http://github.com/kingBook/Fr ...
- .net上的 jpa
还没试过,有空试试: NPersistence ORSQL
- 什么是 BULK INSERT
MSDN的解释: 在 SQL Server 中以用户指定的格式将数据文件导入到数据库表或视图中. 语法: BULK INSERT [ database_name . [ schema_name ] . ...
- 有关于分布式和SOA的理解
我的理解分布式和SOA都差不多,类似功能独立分开.举个例子,做一辆车,按照传统模式,先生产车架,然后生产车轮..然后一辆车完成.现在分布式就是生产车架与生产车轮分离,所有的材料 就是最后一次组装的时候 ...
- platform 系统是windows还是liunx
import platform # 判断当前代码运行的系统是windows还是liunx print(platform.architecture()) print(platform.platform( ...
- 基础的正则表达式与re模块(2)
一.元字符 字符组是元字符中的一个.在字符组中所有的字符都可以匹配任意一个字符位置上能出现的内容,如果在字符串中有任意一个字符是字符组中的内容,那么就是匹配上的项. [0-9] [a-z] ...
- OpenCV SVM
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <ope ...
- 苹果笔记本 如何配置成php开发系统
方法一 启动内置的apace 打开终端输入命令 停止服务:sudo /usr/sbin/apachectl stop 开启服务:sudo /usr/sbin/apachectl start 重启服务: ...