recursively chmod

I was attempting to chmod folders and also documents with:

find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

Yet I was asking yourself:

  1. Just how to do it in one line making use of find and also leaving out the directory sites . and also ..

  2. Which method is much better, find -exec or xargs?

2019-05-04 13:15:59
Source Share
Answers: 4

You can do this with the called debates to chmod:

 chmod u=rwX,go=rX {}

The resources X is the key component below which transforms the approval to executable just if it is a directory site. See the manual page for even more information.

2019-05-08 23:24:11

Sherlock obtained (1 ), for (2) xargs is usually better as it permits even more practical syntax and also much less covering conjuration expenses. Recognize the -print0 and also -0 alternatives to find and also xargs specifically as courses with rooms and also unique personalities can fumble the jobs.

For a one - time run, the distinction actually should not matter unless you are chmodding a massive tree. If you do this usually adequate to define right into a manuscript, I would certainly make use of xargs.

2019-05-08 23:23:46

Is making use of find or xargs required?

Otherwise, you can make use of :

chmod -R u=rwX,go=rX *
2019-05-08 23:02:29
find . -type d -exec chmod 755 {} + -or -type f -exec chmod 644 {} +

find ... -exec ... + resembles find ... -exec ... \; other than that the command is implemented just as soon as per huge set of matching documents.

Once, find OPTIONS... -exec COMMAND... \; needed to act upon one documents at once. So xargs was designed to team activities for performance. Yet xargs presented its very own share of problem : it anticipates input that is priced estimate in such a way that find can not generate. So find OPTIONS... | xargs COMMAND... is no excellent unless you recognize that your documents names do not have any one of '"\ or whitespace.

After that GNU designed find OPTIONS... -print0 | xargs -0 COMMAND..., which permits any kind of personality to show up in a documents name. Yet it took a long period of time for any person else to embrace it, and also in the meanwhile Sun (I assume) designed find OPTIONS... -exec COMMAND... +, which does the very same group work as xargs, without the included difficulties (longer command line, restriction to one per find command). Currently find ... -exec ... + is typical (it's in Single Unix v3), and also extra extensively readily available than xargs -0. Unless you need to keep compatibility with an old Linux system, simply forget xargs.

2019-05-08 22:40:44