每天一个Linux之chown命令
2016-01-04 15:52
986 查看
chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID;组可以是组名或者组ID;文件是以空格分开的要改变权限的文件列表,支持通配符。系统管理员经常使用chown命令,在将文件拷贝到另一个用户的名录下之后,让用户拥有使用该文件的权限。
1.命令格式:
chown [选项]... [所有者][:[组]] 文件...
[b]2.命令功能:[/b]
[b] [b]通过chown改变文件的拥有者和群组。在更改文件的所有者或所属群组时,可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。[/b][/b]
[b][b]3.命令参数:[/b][/b]
[b][b] 必要参数:[/b][/b]
[b][b] -c 显示更改的部分的信息[/b][/b]
[b][b] -f 忽略错误信息[/b][/b]
[b][b] -h 修复符号链接[/b][/b]
[b][b] -R 处理指定目录以及其子目录下的所有文件[/b][/b]
[b][b] -v 显示详细的处理信息[/b][/b]
[b][b] -deference 作用于符号链接的指向,而不是链接文件本身[/b][/b]
[b][b][b]4.使用实例:[/b][/b][/b]
[b][b][b][b]实例1:改变属主和属组[/b][/b][/b][/b]
[b][b][b][b]命令:[/b][/b][/b][/b]
chown centos:centos text
[b]输出:[/b]
实例2:仅改变属主
[b][b][b][b]命令:[/b][/b][/b][/b] chown :centos text[b]输出:[/b]
实例3:改变指定目录以及其子目录下的所有文件的属主和属组
命令:
chown -R -v root:mail nginx-1.8.0
输出:
1.命令格式:
chown [选项]... [所有者][:[组]] 文件...
[b]2.命令功能:[/b]
[b] [b]通过chown改变文件的拥有者和群组。在更改文件的所有者或所属群组时,可以使用用户名称和用户识别码设置。普通用户不能将自己的文件改变成其他的拥有者。其操作权限一般为管理员。[/b][/b]
[b][b]3.命令参数:[/b][/b]
[b][b] 必要参数:[/b][/b]
[b][b] -c 显示更改的部分的信息[/b][/b]
[b][b] -f 忽略错误信息[/b][/b]
[b][b] -h 修复符号链接[/b][/b]
[b][b] -R 处理指定目录以及其子目录下的所有文件[/b][/b]
[b][b] -v 显示详细的处理信息[/b][/b]
[b][b] -deference 作用于符号链接的指向,而不是链接文件本身[/b][/b]
[b][b][b]4.使用实例:[/b][/b][/b]
[b][b][b][b]实例1:改变属主和属组[/b][/b][/b][/b]
[b][b][b][b]命令:[/b][/b][/b][/b]
chown centos:centos text
[b]输出:[/b]
[BEGIN] 2016/1/4 15:36:58 [root@localhost ~]# ll total 76 -rw-------. 1 root root 3345 Dec 29 21:22 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jan 3 04:50 ddd.ddd -rw-r--r--. 1 root root 18 Jan 3 21:43 dump.rdb -rw-r--r--. 1 root root 39935 Dec 29 21:22 install.log -rw-r--r--. 1 root root 9154 Dec 29 21:19 install.log.syslog drwxr-xr-x. 9 1001 1001 4096 Dec 31 00:01 nginx-1.8.0 drwxrwxrwx. 6 root root 4096 Dec 29 22:33 redis-3.0.6 -rw-r--r--. 1 root root 0 Jan 3 04:58 testfile -rw-r--r--. 1 root root 0 Jan 3 05:02 testfile1 drwxr-xr-x. 6 root root 4096 Jan 3 06:04 text -rw-rw-r--. 1 root root 0 Jan 3 04:48 text.ddd ---xr--r--. 1 root root 0 Jan 3 04:43 text.txt [root@localhost ~]# chown centos:centos text [root@localhost ~]# ll total 76 -rw-------. 1 root root 3345 Dec 29 21:22 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jan 3 04:50 ddd.ddd -rw-r--r--. 1 root root 18 Jan 3 21:43 dump.rdb -rw-r--r--. 1 root root 39935 Dec 29 21:22 install.log -rw-r--r--. 1 root root 9154 Dec 29 21:19 install.log.syslog drwxr-xr-x. 9 1001 1001 4096 Dec 31 00:01 nginx-1.8.0 drwxrwxrwx. 6 root root 4096 Dec 29 22:33 redis-3.0.6 -rw-r--r--. 1 root root 0 Jan 3 04:58 testfile -rw-r--r--. 1 root root 0 Jan 3 05:02 testfile1 drwxr-xr-x. 6 centos centos 4096 Jan 3 06:04 text -rw-rw-r--. 1 root root 0 Jan 3 04:48 text.ddd ---xr--r--. 1 root root 0 Jan 3 04:43 text.txt [END] 2016/1/4 15:37:37
实例2:仅改变属主
[b][b][b][b]命令:[/b][/b][/b][/b] chown :centos text[b]输出:[/b]
[BEGIN] 2016/1/4 15:41:02 root@localhost ~]# ll total 76 -rw-------. 1 root root 3345 Dec 29 21:22 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jan 3 04:50 ddd.ddd -rw-r--r--. 1 root root 18 Jan 3 21:43 dump.rdb -rw-r--r--. 1 root root 39935 Dec 29 21:22 install.log -rw-r--r--. 1 root root 9154 Dec 29 21:19 install.log.syslog drwxr-xr-x. 9 1001 1001 4096 Dec 31 00:01 nginx-1.8.0 drwxrwxrwx. 6 root root 4096 Dec 29 22:33 redis-3.0.6 -rw-r--r--. 1 root root 0 Jan 3 04:58 testfile -rw-r--r--. 1 root root 0 Jan 3 05:02 testfile1 drwxr-xr-x. 6 centos centos 4096 Jan 3 06:04 text -rw-rw-r--. 1 root root 0 Jan 3 04:48 text.ddd ---xr--r--. 1 root root 0 Jan 3 04:43 text.txt [root@localhost ~]# chown :centos text.ddd [root@localhost ~]# ll total 76 -rw-------. 1 root root 3345 Dec 29 21:22 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jan 3 04:50 ddd.ddd -rw-r--r--. 1 root root 18 Jan 3 21:43 dump.rdb -rw-r--r--. 1 root root 39935 Dec 29 21:22 install.log -rw-r--r--. 1 root root 9154 Dec 29 21:19 install.log.syslog drwxr-xr-x. 9 1001 1001 4096 Dec 31 00:01 nginx-1.8.0 drwxrwxrwx. 6 root root 4096 Dec 29 22:33 redis-3.0.6 -rw-r--r--. 1 root root 0 Jan 3 04:58 testfile -rw-r--r--. 1 root root 0 Jan 3 05:02 testfile1 drwxr-xr-x. 6 centos centos 4096 Jan 3 06:04 text -rw-rw-r--. 1 root centos 0 Jan 3 04:48 text.ddd ---xr--r--. 1 root root 0 Jan 3 04:43 text.txt [END] 2016/1/4 15:41:45说明:原始的属主不变,只更改属组。(ps:或者更改属主chown centos:textddd 只更改文件的属主)
实例3:改变指定目录以及其子目录下的所有文件的属主和属组
命令:
chown -R -v root:mail nginx-1.8.0
输出:
[BEGIN] 2016/1/4 15:47:51 [root@localhost ~]# ll total 76 -rw-------. 1 root root 3345 Dec 29 21:22 anaconda-ks.cfg -rw-r--r--. 1 root root 0 Jan 3 04:50 ddd.ddd -rw-r--r--. 1 root root 18 Jan 3 21:43 dump.rdb -rw-r--r--. 1 root root 39935 Dec 29 21:22 install.log -rw-r--r--. 1 root root 9154 Dec 29 21:19 install.log.syslog drwxr-xr-x. 9 1001 1001 4096 Dec 31 00:01 nginx-1.8.0 drwxrwxrwx. 6 root root 4096 Dec 29 22:33 redis-3.0.6 -rw-r--r--. 1 root root 0 Jan 3 04:58 testfile -rw-r--r--. 1 root root 0 Jan 3 05:02 testfile1 drwxr-xr-x. 6 centos centos 4096 Jan 3 06:04 text -rw-rw-r--. 1 root centos 0 Jan 3 04:48 text.ddd ---xr--r--. 1 root root 0 Jan 3 04:43 text.txt [root@localhost ~]# chown -R -v root:centos nginx-1.8.0 changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_ssl_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_chunked_filter_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_log_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_gzip_static_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_empty_gif_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_range_filter_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_autoindex_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_rewrite_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_fastcgi_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_stub_status_module.o' to root:centos changed ownership of `nginx-1.8.0/objs/src/http/modules/ngx_http_upstream_keepalive_module.o' to root:centos [root@localhost ~]# [END] 2016/1/4 15:48:48
相关文章推荐
- Linux socket 初步
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 设计模式之行为型模式 - 调用行为的传递问题