在所有.htaccess文件上设置chmod

时间:2014-09-11 18:27:24

标签: apache .htaccess chmod

如何找到chmod 444并将其设置为目录中的所有.htaccess文件(出于安全目的)?

感谢。

1 个答案:

答案 0 :(得分:5)

如果您可以访问SSH,则可以执行以下操作:

find . -name .htaccess | xargs chmod 444

对从您运行命令的当前目录中找到的所有chmod文件递归执行.htaccess

如果要指定文件夹,可以这样做:

find /home/your_account/public_html -name .htaccess | xargs chmod 444

您还可以在使用命令之前列出文件,以确保它符合您的需求:

find . -name .htaccess -print

或使用文件夹路径:

find /home/your_account/public_html -name .htaccess -print

例如,如果您在以下位置运行了第一个提到的命令:

/home/your_account/public_html

它会从该文件夹和.htaccess上方的任何其他文件夹中提供chmod 444个文件,因此:

/home/your_account/public_html
/home/your_account/public_html/other_dir
/home/your_account/public_html/other_dir2
/home/your_account/public_html/other_dir/other_inner_dir

等等。