[英]How to implement parallelism in this bash one-liner
有人可以帮我整理一下这个肮脏的单行代码并实现并行性吗?
find . -name "*.php" -exec rename 's/\.php$/.txt/' '{}' \; && chown www-data:www-data -R * && chmod 0755 -R * && find . -name "*.html" -exec rename 's/\.html$/.txt/' '{}' \; && find . -name ".htaccess" -delete
Adding parallelism to an I/O bound set of tasks will only make it slower if the parallel tasks share the same I/O channel. 如果并行任务共享相同的I / O通道,则将并行性添加到I / O绑定的任务集只会使其变慢。 (Hint: they do here.)
(提示:他们在这里。)
The only useful optimization you can do here is reduce the number of times you traverse the same directory tree. 您可以在此处进行的唯一有用的优化是减少遍历同一目录树的次数。
find . -exec chown www-data:www-data {} \; \
-exec chmod 0755 {} \; \
\( -name "*.php" -exec rename 's/\.php$/.txt/' '{}' \; \
-o -name "*.html" -exec rename 's/\.html$/.txt/' '{}' \; \
-o -name ".htaccess" -delete \)
This could still be tweaked but eg avoiding to chown
a file you know you are going to delete is small potatoes compared to reducing five directory traversals to one. 仍然可以对此进行调整,但是与将五个目录遍历减少为一个相比,避免对已知要删除的文件进行
chown
是小土豆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.