LoginSignup
10
9

More than 5 years have passed since last update.

MacでchmodがOperation not permittedの時はfile flagも確認しよう

Posted at

事象

Mac(High Shierra)で、ファイルをchmodすると以下のエラーになりました。

$ls -l
-r-xr-xr-x  1 myuser  staff  655 11  8 14:46 hogehoge.txt

$sudo chmod 775 hogehoge.txt
chmod: Unable to change file mode on hogehoge.txt: Operation not permitted

SIPの保護対象ファイルでもないはずだし、はて?

原因

ファイルがロックされているだけでした。
Unixのノリでファイルを扱うと、時々Mac的な落とし穴にはまります。

$ls -lO
-r-xr-xr-x  1 myuser  staff  uchg 655 11  8 14:46 hogehoge.txt

Oオプションでファイルフラグを表示させています。

対処

chflagsでロックを解除します。

$chflags nouchg hogehoge.txt

$ls -lO
-r-xr-xr-x  1 aa516435  staff  - 655 11  8 14:46 hogehoge.txt

参照

Why does chown report “Operation not permitted” on OS X?

10
9
0

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
10
9