如何使用chmod
命令在Linux
终端中将所有文件更改为644,所有文件夹更改为755?
如何使用chmod
命令在Linux
终端中将所有文件更改为644,所有文件夹更改为755?
一种方法是使用find:
find /desired_location -type d -print0 | xargs -0 chmod 0755
find /desired_location -type f -print0 | xargs -0 chmod 0644
sudo find /your/location -type f -exec chmod 644 {} \;
;对于目录,使用sudo find /your/location -type d -exec chmod 755 {} \;
。 - NineCattoRuleschmod -R a=r,u+w,a+X /foo
比它更好? - Peter Krausssudo chmod -R 755 "/your/location"; sudo find "/your/location" -type f -exec chmod 644 {} \;
。(并不会有太大的区别) - WoodrowShigeru最简单的方法是这样做:
chmod -R u+rwX,go+rX,go-w /path/to/dir
这基本意味着:
通过给出以下内容来递归地更改文件模式:
u
ser:拥有r
ead、w
rite和eX
ecute权限,g
roup和o
ther用户:拥有r
ead和eX
ecute权限,但没有-w
rite权限。请注意,X
将使目录可执行,但不会使文件可执行,除非它已经是可搜索/可执行的。
+X
- 如果任何人可以搜索/执行,则使目录或文件对每个人都可搜索/执行。
有关更多详细信息,请查看man chmod
。
另请参见:如何递归地修改所有目录的权限而排除所有文件?(SU)
我能想到的最短的是:
chmod -R a=r,u+w,a+X /foo
这个工具可以在GNU/Linux上使用,我相信它通常也可以在Posix上使用(从我的阅读中得知: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html)。
它的功能是:
重要的是,步骤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 /A -type X -exec chmod Y '{}' \;
- Michael Stumpfl使用以下方法一次完成两个任务:
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.
http://superuser.com
:P 但这个问题在这里帮到了我,谢谢。 - emotalitychmod -R u+rwX,go+rX,go-w /foo
。该命令将递归修改/foo目录及其内容的权限。其中,"u+rwX"将所有者(user)的读写权限设置为可读可写可执行,其中大写的X表示如果文件是可执行文件或目录,则自动添加执行权限;"go+rX"将组(group)和其他人(others)的读权限设置为可读,同时同样包括上述针对可执行文件和目录的规则;"go-w"将组和其他人的写权限设置为不可写入。 - kenorb