如何使目录世界下的所有文件在Linux上可读?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13119219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:38:49  来源:igfitidea点击:

How to make all files under a directory world readable on linux?

linuxbashubuntucommand-linechmod

提问by Rorchackh

I want to make all files (and directories) under a certain directory world readable without having to chmod each file on its own. it would be great if there is an option to also do this recursively (look under folders and chmod 666 all files under it)

我想让某个目录下的所有文件(和目录)都可读,而不必单独对每个文件进行 chmod。如果有一个选项也可以递归地执行此操作,那就太好了(查看文件夹和 chmod 666 下的所有文件)

采纳答案by Rorchackh

man 3 chmodcontains the information you are looking for.

man 3 chmod包含您要查找的信息。

chmod -R +r directory

the -Roption tells chmodto operate recursively.

-R选项告诉chmod递归操作。

回答by F. Hauri

As a directory could contain links and/or bind mounts, the use of findcould ensure a finest granularity in what to do and what to not do....

由于目录可以包含链接和/或绑定挂载,因此使用find可以确保在做什么和不做什么方面有最精细的粒度....

find directory \( -type f -o -type d \) -print0 |
    xargs -0 chmod ugo+r

To exclude paths under mount points:

排除挂载点下的路径:

find directory -mount \( -type f -o -type d \) -print0 |
    xargs -0 chmod ugo+r

To exclude some specific files (.htaccess for sample):

要排除某些特定文件(示例为 .htaccess):

find directory \( -type f -o -type d \) ! -name '.htaccess' -print0 |
    xargs -0 chmod ugo+r