如何指定僅用於 chmod 的資料夾

如何指定僅用於 chmod 的資料夾

我有一個 30GB 的網站,其中包含大量資料夾和檔案。我希望所有資料夾都具有 745 權限,所有檔案都具有 644 權限chmod -R 745 public_html/。如何使用 chmod 將所有資料夾(僅)更改為此權限?

答案1

除非您故意不希望群組成員存取該目錄(這將是一種不尋常的情況),否則您應該使用755目錄。

您可以使用find

對於文件:

find /path/to/public_html/ -type f -exec chmod 0644 {} +

對於目錄(使用 755):

find /path/to/public_html/ -type d -exec chmod 0755 {} +
  • -type f只會找到文件並chmod 0644相應執行

  • -type d將僅查找目錄並chmod 0755對其執行。

相關內容