linux – 使递归chmod更快

我有一个安装脚本解压缩目录,然后递归chmod其内容.

我很惊讶它需要几乎10倍的时间来解压缩,运行以下两个命令:

find $dir -type f -exec chmod a+r "{}" \;
find $dir -type d -exec chmod a+rx "{}" \;

我做错了什么,是否有更快的方法来更改所有文件和目录的chmod?

解决方法

您可以使用chmod的X标志去掉find命令:
execute/search only if the file is a directory or already has execute permission for some user (X)

这允许您使用单个命令在文件和目录上设置相同的权限,目录另外可执行:

$chmod -R a+rX $dir

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...