chmod+find如何批量授权

发布时间:2022-01-14 09:21:58 作者:小新
来源:亿速云 阅读:140

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

这两张图是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如何批量授权”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

推荐阅读:
  1. Linux环境使用授权码实现软件授权
  2. Spring Security授权方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

chmod find

上一篇:将系统分解为微服务的策略是什么

下一篇:springboot整合quartz定时任务框架的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》