chmod
パーミッション
書き方
chmod 755 [path]ファイルとディレクトリの権限ビットを決めます。chmod -R 755 は普通のファイルまで実行可能にしてしまうので、ファイルを触らせたくなければ大文字の X を使います。
よく使うオプション
| オプション | 意味 |
|---|---|
| 0755 | Numeric: owner, group, others, each read 4 + write 2 + execute 1 |
| u+w | Symbolic: who (u g o a), then + - =, then r w x |
| +x | Add the execute bit, the usual fix for a script |
| -R | Apply to a whole tree |
| +X | Execute for directories only, never for plain files |
| -v | Name each file whose mode changed |
| -h | BSD and macOS: change the symlink itself, not its target |
例
chmod +x deploy.shMakes the script runnable.
chmod -R u+rwX,go+rX,go-w site/Capital X keeps files non-executable.
chmod 600 ~/.ssh/id_ed25519What ssh insists on for a private key.
数字モードと記号モードは同じものを指します。755 と u=rwx,go=rx は同じ意味です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. chmod は何をしますか。
ファイルとディレクトリの権限ビットを決めます。chmod -R 755 は普通のファイルまで実行可能にしてしまうので、ファイルを触らせたくなければ大文字の X を使います。
Q. どう打ちますか。
chmod 755 [path] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man chmod にあります。このコマンドはパーミッションの仲間です。
関連するコマンド
man ページ: man chmod