Linux:仅将权限设置为目录

时间:2021-12-31 16:46:13

I have to change the permissions of the htdocs directory in apache to a certain group and with certain read/write/execute.

我必须将apache中htdocs目录的权限更改为某个组并具有某些读/写/执行权限。

The directories need to have 775 permissions and the files need to have 664.

目录需要有775个权限,文件需要有664个。

If I do a recursive 664 to the htdocs, then all files and directories will change to 664.

如果我对htdocs执行递归664,那么所有文件和目录都将更改为664。

I don't want to change the directories manually.

我不想手动更改目录。

Is there any way to change only files or directories?

有没有办法只更改文件或目录?

6 个解决方案

#1


16  

Use find's -type option to limit actions to files and directories. Use the -o option to specify alternate actions for different types, so you only have to run find once, rather than separately for each type.

使用find的-type选项将操作限制为文件和目录。使用-o选项为不同类型指定备用操作,因此您只需运行一次查找,而不是为每种类型单独运行。

find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

#2


38  

chmod can actually do this itself; the X symbolic permission means "execute, if it makes sense" which generally means on directories but not files. So, you can use:

chmod实际上可以做到这一点; X符号权限意味着“执行,如果它有意义”,这通常意味着在目录而不是文件。所以,你可以使用:

chmod -R u=rwX,go=rX /path/to/htdocs

The only potential problem is that if any of the plain files already have execute set, chmod assumes it's intentional and keeps it.

唯一可能的问题是,如果任何普通文件已经有执行集,则chmod假定它是有意的并保留它。

#3


3  

Use find to search for directories and apply chmod on them:

使用find搜索目录并在其上应用chmod:

find -type d | xargs chmod 775

Use type f for file:

使用类型f表示文件:

find -type f | xargs chmod 775

#4


1  

try:

尝试:

find htdocs -type d -exec chmod 775 {} +

#5


1  

Gordon's answer above is correct, but if you're trying to lock down access to a directory tree, it leaves scripts that are executable to the owner also executable to whoever has been granted the capital X.

Gordon上面的答案是正确的,但是如果你试图锁定对目录树的访问权限,那么它会向所有者执行可执行的脚本,这些脚本也可以执行给已被授予大写字母X的任何人。

Using

运用

find -type d exec chmod 775 {} +

or

要么

find -type d exec chmod 755 {} +

is safer.

更安全。

#6


0  

I use something similar to the solution provided by Gordon:

我使用类似于戈登提供的解决方案:

chmod -R ug=rw,o=r,a+X /path/to/folder/

It should always set 775 for folders and 664 for files, even if the execute permission was previosly set for some file

它应始终为文件夹设置775,为文件设置664,即使为某些文件预先设置了执行权限

#1


16  

Use find's -type option to limit actions to files and directories. Use the -o option to specify alternate actions for different types, so you only have to run find once, rather than separately for each type.

使用find的-type选项将操作限制为文件和目录。使用-o选项为不同类型指定备用操作,因此您只需运行一次查找,而不是为每种类型单独运行。

find htdocs -type f -exec chmod 664 {} + -o -type d -exec chmod 775 {} +

#2


38  

chmod can actually do this itself; the X symbolic permission means "execute, if it makes sense" which generally means on directories but not files. So, you can use:

chmod实际上可以做到这一点; X符号权限意味着“执行,如果它有意义”,这通常意味着在目录而不是文件。所以,你可以使用:

chmod -R u=rwX,go=rX /path/to/htdocs

The only potential problem is that if any of the plain files already have execute set, chmod assumes it's intentional and keeps it.

唯一可能的问题是,如果任何普通文件已经有执行集,则chmod假定它是有意的并保留它。

#3


3  

Use find to search for directories and apply chmod on them:

使用find搜索目录并在其上应用chmod:

find -type d | xargs chmod 775

Use type f for file:

使用类型f表示文件:

find -type f | xargs chmod 775

#4


1  

try:

尝试:

find htdocs -type d -exec chmod 775 {} +

#5


1  

Gordon's answer above is correct, but if you're trying to lock down access to a directory tree, it leaves scripts that are executable to the owner also executable to whoever has been granted the capital X.

Gordon上面的答案是正确的,但是如果你试图锁定对目录树的访问权限,那么它会向所有者执行可执行的脚本,这些脚本也可以执行给已被授予大写字母X的任何人。

Using

运用

find -type d exec chmod 775 {} +

or

要么

find -type d exec chmod 755 {} +

is safer.

更安全。

#6


0  

I use something similar to the solution provided by Gordon:

我使用类似于戈登提供的解决方案:

chmod -R ug=rw,o=r,a+X /path/to/folder/

It should always set 775 for folders and 664 for files, even if the execute permission was previosly set for some file

它应始终为文件夹设置775,为文件设置664,即使为某些文件预先设置了执行权限