出处:http://blog.chinaunix.net/uid-298599-id-2443098.html
1. 查看目录及当前文件
[root@localhost yuechaotian]# pwd /home/yuechaotian [root@localhost yuechaotian]# ll 总用量 8 drwxr-xr-x 3 root root 4096 12月 7 14:52 study drwxr-xr-x 2 root root 4096 12月 9 21:43 test [root@localhost yuechaotian]# ll test 总用量 12 -rwxr-xr-x 1 root root 11742 12月 9 21:43 conf.rd |
2. 只改变目录test的用户及群组,并未改变目录test下的文件用户及群组
[root@localhost yuechaotian]# chown yuechaotian:dba test [root@localhost yuechaotian]# ll 总用量 8 drwxr-xr-x 3 root root 4096 12月 7 14:52 study drwxr-xr-x 2 yuechaotian dba 4096 12月 9 21:43 test [root@localhost yuechaotian]# ll test 总用量 12 -rwxr-xr-x 1 root root 11742 12月 9 21:43 conf.rd |
3. 使用参数 -R,改变目录 test 及其文件用户和群组
[root@localhost yuechaotian]# chown root:root test [root@localhost yuechaotian]# ll 总用量 8 drwxr-xr-x 3 root root 4096 12月 7 14:52 study drwxr-xr-x 2 root root 4096 12月 9 21:43 test [root@localhost yuechaotian]# chown -R yuechaotian:dba test [root@localhost yuechaotian]# ll 总用量 8 drwxr-xr-x 3 root root 4096 12月 7 14:52 study drwxr-xr-x 2 yuechaotian dba 4096 12月 9 21:43 test [root@localhost yuechaotian]# ll test 总用量 12 -rwxr-xr-x 1 yuechaotian dba 11742 12月 9 21:43 conf.rd |
在 chmod 中使用 -R 参数,能达到同样的效果:该文件夹内的所有文件/文件夹都改为指定的权限.