开发者

Ways to set x bits on only dirs besides using find

Often, I find myself needing to make a tree of directories executable for someone, ie:

find . -type d -exec chmod ug+x {} \;

But I don't like the overhead of find, and running a "new" chmod for every dir.

You folks have preferred alternatives? Why开发者_开发技巧?


This one should have much less overhead:

find . -type d -exec chmod ug+x {} +

(Replaced \; by +.) This does the same thing, but calls chmod with many directories at once, which eliminates the overhead of calling chmod multiple times.

From the manpage:

-exec command {} +  

This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invocations of the command will be much less than the number of matched files. The command line is built in much the same way that xargs builds its command lines. Only one instance of {} is allowed within the command. The command is executed in the starting directory.

This is quite similar to this:

find . -type d -print0|xargs -0 chmod ug+x


This doesn't do exactly what you want, but it's fast and simple and may be close enough:

chmod -R ug+X .

The capital X permission option tells chmod to grant execute access only if it makes sense -- if the item is a directory, or already has at least one execute access enabled (i.e. if it appears to be an executable file).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜