资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

chmod+find如何批量授权

这篇文章将为大家详细讲解有关chmod+find如何批量授权,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

发展壮大离不开广大客户长期以来的信赖与支持,我们将始终秉承“诚信为本、服务至上”的服务理念,坚持“二合一”的优良服务模式,真诚服务每家企业,认真做好每个细节,不断完善自我,成就企业,实现共赢。行业涉及航空箱等,在成都网站建设成都全网营销推广、WAP手机网站、VI设计、软件开发等项目上具有丰富的设计经验。

这两张图是test 这个文件夹下的目录结构图以及权限图。那么接下来我要将test这个目录以及子目录的所有.sh 的文件设置为只有可执行权限要怎么设置呢?执行以下命令后会发现 tesh.sh 和./test1/test1.sh 的权限已经变成---x--x--x 而其它保持不变

find . -name "*.sh" -exec chmod 111 {} \;
total 0
drwxr-xr-x 2 root root 38 Sep 29 10:31 test1
drwxr-xr-x 2 root root  6 Sep 29 10:13 test2
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.tx

find .  -name "*.sh"  与 find . -name *.sh 的区别是少了个双引号,结果就是一个递归,一个不递归。

有人会说了 chmod 有个 -R 参数就可以实现递归了。 但是chmod -R 实现的是无差别攻击所以并不适用,以上授权命令还可以写成这样。效果上是一样的。

把 文件里面.txt 改成执行权限

[root@oracle1 test]# chmod 111 `find . -name "*.txt"`
[root@oracle1 test]# ll
total 0
d--x--x--x 2 root root 38 Sep 29 10:31 test1
d--x--x--x 2 root root  6 Sep 29 10:13 test2
-rw-r--r-- 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

那么问题又来了 我一个目录下要是只有文件与文件夹的区别呢?  好的 ,这个时候你就可以用 find  命令的 -type 参数了 type 后面 d代表目录,f 代表 文件

给文件设置为只有可执行权限

[root@oracle1 test]# chmod 111 `find . -type f`
[root@oracle1 test]# ll
total 0
d--x--x--x 2 root root 38 Sep 29 10:31 test1
d--x--x--x 2 root root  6 Sep 29 10:13 test2
---x--x--x 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

给目录设置为755权限

[root@oracle1 test]# chmod 755 `find . -type d`
[root@oracle1 test]# ll
total 0
drwxr-xr-x 2 root root 38 Sep 29 10:31 test1
drwxr-xr-x 2 root root  6 Sep 29 10:13 test2
---x--x--x 1 root root  0 Sep 29 10:38 test.bash
---x--x--x 1 root root  0 Sep 29 10:22 test.sh
---x--x--x 1 root root  0 Sep 29 10:38 test.txt

关于“chmod+find如何批量授权”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


网页题目:chmod+find如何批量授权
网页网址:http://cdkjz.cn/article/jjeois.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220