LoginSignup
52
59

More than 5 years have passed since last update.

パーミッションやオーナーを一括で変更する

Last updated at Posted at 2016-03-06

こんにちは :whale2:
たとえばなしですが、若者がドキュメントルート以下のディレクトリやファイルのオーナーやパーミッションをゆるくしてしまった1ので、何とかするのです。

オーナー変更

(例) /usr/share/nginx/html ディレクトリ以下のファイル/ディレクトリを全て
nginx ユーザ、nginx グループのものに変更。

$ chown -R nginx:nginx /usr/share/nginx/html

パーミッション変更

(例) /usr/share/nginx/html ディレクトリ以下の、ディレクトリを755、ファイルを644に変更。

findの-execオプションで処理する方式
$ find /usr/share/nginx/html -type d -exec chmod 755 {} \;
$ find /usr/share/nginx/html -type f -exec chmod 644 {} \;
findの結果をパイプでxargsに与える方式
$ find /usr/share/nginx/html -type d -print0 | xargs -0 chmod 755
$ find /usr/share/nginx/html -type f -print0 | xargs -0 chmod 644

おわりです。

参考と注釈


  1. オーナーがファイルアップロード用ユーザで、パーミッションが全部777とか 

52
59
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
52
59