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 ...
随机推荐
- C语言复习:结构体
结构体专题 01.结构体类型定义及结构体变量定义 char c1,char c2, char name[62]; int age char name[62]; int age,char ...
- 观察者模式——Head First
一.定义 观察者模式(Observer Pattern)定义了对象之间的一对多依赖,这样一来,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新. 二.类图 三.气象站 //Subject p ...
- asp.net4.0
asp.net4.0安装路径:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
- js高级-闭包
function foo(x){ var tmp = 3; return function(y){ //把一个函数作为返回值,定义时候的作用域 console.log(x+y+(++tmp)) //+ ...
- struts原理图
n the diagram, an initial request goes to the Servlet container (such as Jetty or Resin) which is pa ...
- 2017秋季面向对象程序设计(Java)教材、教学纲要、考核要求
教材简况 凯 S.霍斯特曼 (Cay S. Horstmann)(作者), 周立新(译者), Java核心技术(卷1):基础知识(原书第10版) , 2016年9月1出版 本书包括两卷,选做教材的是卷 ...
- ofstream和ifstream
ofstream(输出流)是从内存到硬盘,ifstream(输入流)是从硬盘到内存. //#include<iostream> #include<fstream> using ...
- vue 模拟下拉树
// 使用vue 做表格部分其他部分暂不修改 var app = new Vue({ el: "#freightTbl", watch: { //监听表格数据的变化[使用 watc ...
- Vue-axios快速上手(转)
引入方式: 1 2 3 4 5 $ npm install axios $ cnpm install axios //taobao源 $ bower install axios 或者使用cdn: &l ...
- php抓取股票数据
public function stock(){ $curl = new Curl(); $curl->setUserAgent('Mozilla/5.0'); $curl->get('h ...