如何一步更改一个文件夹及其子文件夹/文件的权限? [英] How to change permissions for a folder and its subfolders/files in one step?

查看:56
本文介绍了如何一步更改一个文件夹及其子文件夹/文件的权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Linux中一步(命令)更改文件夹及其所有子文件夹和文件的权限.

I would like to change the permissions of a folder and all its subfolders and files in one step (command) in Linux.

我已经尝试了以下命令,但是它仅适用于提到的文件夹:

I have already tried the below command but it works only for the mentioned folder:

chmod 775 /opt/lampp/htdocs

是否可以为/opt/lampp/htdocs 及其所有内容(包括子文件夹和文件)设置 chmod 755 ?

Is there a way to set chmod 755 for /opt/lampp/htdocs and all of its content including subfolders and files?

此外,将来,如果我在 htdocs 内创建一个新文件夹或文件,如何将其权限自动设置为 755 ?

Also, in the future, if I create a new folder or file inside htdocs, how can the permissions of that automatically be set to 755?

我也查看了此链接:

如何在LINUX终端中设置默认的CHMOD?

推荐答案

其他答案是正确的,因为 chmod -R 755 将对树中的所有文件和子文件夹设置这些权限.但是,为什么你要?这对于目录可能有意义,但是为什么要在所有文件上设置execute位?

The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?

我怀疑您真正想做的是将目录设置为755,或者不理会这些文件,或者将它们设置为644.为此,您可以使用 find 命令.例如:

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:

要将所有目录更改为755( drwxr-xr-x ):

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

要将所有文件更改为644( -rw-r--r-):

To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

这篇关于如何一步更改一个文件夹及其子文件夹/文件的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆