我有一个安装脚本unzip
sa目录,然后recursion地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
你可以做以下事情(假设Linux):
cd $dir chmod -R a+r . find . -type d -print0 | xargs -0 chmod a+x
这应该比你在问题中指出的两个命令的组合要快得多。
改用tar
。 特别是使用-p, --preserve-permissions, --same-permissions
标志。
你不能直接压缩它,但-z, --gzip
, -j, --bzip2
或-J, --xz
应该工作得不错。 如果你真的必须有拉链,那只有一个|
远。
考虑到你的命令,我认为你正在花时间等待find而不是chmod。
尝试:
chmod -R a+r $dir
“-R”表示recursion
当你运行的解压缩和其他命令前言
time
要测量各种命令花费的时间。