Ror*_*ckh 28 linux bash ubuntu command-line chmod
我想让某个目录下的所有文件(和目录)都可以读取,而不必自己chmod每个文件.如果有一个选项也可以递归地执行此操作(看看文件夹和chmod 666下的所有文件)会很棒
小智 35
man 3 chmod
包含您要查找的信息.
chmod -R +r directory
Run Code Online (Sandbox Code Playgroud)
该-R
选项告诉chmod
以递归方式操作.
由于目录可以包含链接和/或绑定挂载,因此使用find
可以确保在做什么和不做什么时具有最精细的粒度....
find directory \( -type f -o -type d \) -print0 |
xargs -0 chmod ugo+r
Run Code Online (Sandbox Code Playgroud)
要排除挂载点下的路径:
find directory -mount \( -type f -o -type d \) -print0 |
xargs -0 chmod ugo+r
Run Code Online (Sandbox Code Playgroud)
要排除某些特定文件(.htaccess for sample):
find directory \( -type f -o -type d \) ! -name '.htaccess' -print0 |
xargs -0 chmod ugo+r
Run Code Online (Sandbox Code Playgroud)