如何使用命令提示符将所有文件更改为 644 并将所有文件夹更改为chmod
755 linux
?(终端)
8 回答
一种方法可能是使用 find:
对于目录
find /desired_location -type d -print0 | xargs -0 chmod 0755
对于文件
find /desired_location -type f -print0 | xargs -0 chmod 0644
最简单的方法是:
chmod -R u+rwX,go+rX,go-w /path/to/dir
这基本上意味着:
通过给出以下命令以递归方式对ch
文件进行处理:mod
-R
u
ser:r
ead、w
rite 和 eX
ecute 权限,g
roup 和o
其他用户:r
ead 和 eX
ecute 权限,但不是-w
rite 权限。
请注意,这X
将使目录可执行,但不是文件,除非它已经可搜索/可执行。
+X
- 如果任何人都可以搜索/可执行目录或文件,则让每个人都可以搜索/执行该目录或文件。
请查看man chmod
更多详情。
另请参阅:如何 chmod 除文件以外的所有目录(递归)?在苏
我能想到的最短的是:
chmod -R a=r,u+w,a+X /foo
它适用于 GNU/Linux,而且我一般相信 Posix(根据我的阅读: http: //pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html)。
这是做什么的:
- 将文件/目录设置为 r__r__r__ (0444)
- 为所有者添加 w,以获得 rw_r__r__ (0644)
- 如果是目录(目录为 0755,文件为 0644),则为所有设置执行。
重要的是,第 1 步权限清除所有执行位,因此第 3 步仅添加目录(从不文件)的执行位。此外,所有三个步骤都发生在目录被递归到之前(因此这不等同于例如
chmod -R a=r /foo
chmod -R u+w /foo
chmod -R a+X /foo
因为 a=r 从目录中删除 x ,所以 chmod 不能递归到它们。)
在 https://help.directadmin.com/item.php?id=589他们写道:
如果您需要一种快速的方法将您的 public_html 数据重置为目录的 755 和文件的 644,那么您可以使用以下内容:
cd /home/user/domains/domain.com/public_html
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
我测试并且......它有效!
我最容易记住的是两个操作:
chmod -R 644 dirName
chmod -R +X dirName
+X 只影响目录。
这对我有用:
find /A -type d -exec chmod 0755 {} \;
find /A -type f -exec chmod 0644 {} \;
一次性完成这两项操作:
find -type f ... -o -type d ...
如中,找到类型 f 或类型 d,然后对文件执行第一个...,对目录执行第二个...。具体来说:
find -type f -exec chmod --changes 644 {} + -o -type d -exec chmod --changes 755 {} +
--changes
如果您希望它静默工作,请不要使用。
这也可以工作:
chmod -R 755 * // All files and folders to 755.
chmod -R 644 *.* // All files will be 644.