LoginSignup
0
1

More than 1 year has passed since last update.

権限管理とシェルスクリプト

Last updated at Posted at 2021-12-31

※macOSです

諸々の確認

lsでフル表示させると

ls -l@FTOaehips

以上に加えて

  • -nするとownergroupがIDになる
  • -Rするとディレクトリ構造に対して再帰処理を行う
  • -Sするとサイズでソートする
  • -tすると時間でソートする
    • -tUすると作成created時間でソートする
    • -tcすると変更changed時間でソートする
    • -tuすると接触access時間でソートする
  • -rするとソートが逆転する
  • -Lすると最後までシンボリックリンクを追跡する
    • 表示されるファイル名はそのままだがそれ以外の情報は全て元のファイルのものになる
  • -Wするとホワイトアウトファイルも含めて表示する

ファイルの種類

英字10字の1つ目が該当する

まとめると

1文字目 名称 説明
- 普通のファイル エイリアスもこちらに含まれる,つまりエイリアスを相手にcdはできない /bin/zshとか
b ブロックデバイス(ブロックスペシャル)ファイル ブロックで1区画ずつ(ブロックずつ)データをやりとりする機器やソフトがosのファイルシステムを利用する際に使うエイリアス /dev/disk0とか,こういうのはdiskutil listで見れそう
c キャラクタデバイス(キャラクタスペシャル)ファイル ストリームで1字づつ(キャラクタずつ)データをやりとりする機器やソフトがosのファイルシステムを利用する際に使うエイリアス /dev/nullとか/dev/stdinとか/dev/stdoutとか
d 普通のディレクトリ 特に考えなくて良い /binとか
l シンボリックリンク ls -Lでは表示されない,最後まで追跡されて解決する homebrew/usr/local/binにシンボリックリンクを作りまくる
p FIFO,名前付きパイプ 先入先出(FIFO)でプロセス間の通信を実装できる,あくまで通信の順序によるFIFOでありプロセス立ち上げ順序ではない mkfifo testpipeで試してみると良いかも
s ドメインソケット ファイルシステムを利用してソケットが立ち上がるらしいが…わからん…なにこれ…
w whiteout(ホワイトアウト)ファイル -Wすると表示されるらしいが,恐らくこれは.whファイルではなく.whによって隠されるファイルを指す,やったことはないが事情を鑑みると後者だと思う
ネットで漁った情報を素人考えでまとめると,「互換性のあるファイルシステムを持つ異なるディレクトリ(それを含む別のディスクを新たに外から接続しても良い)を,1つのファイルシステムの特定のディレクトリにユニオンマウントすることで,従来よりも拡張されたストレージが構成できるが,もしそこに(ユニオンマウントする際に)読取のみの設定がされたディレクトリやファイルがある場合は,それを直接的に変更したり削除したりはできない,その代わりに変更や削除を記録できる場所に結果がコピーされるような設定ができて,『変更の場合はそのコピーを作成』・『削除の場合はそれを無視するための.whを作成』する」…ということになる?
BSD系osやLinux系osの一部が使える,UnionFSはその基本の存在でDockerはその改良版のAUFSを経て現在はOverlayFSが推奨されているらしい
osによってはlsが対応していない場合もありそう…

ユニオンマウントの利点?

複数のディスク(物理)を用いる際に

  • 特定のディスクだけにRWを設定してアプリケーションに対するキャッシュサーバとして扱える
    • 書き込み負荷をキャッシュサーバに集中させられる
    • 壊れるディスクを敢えて絞り込めるから管理が楽
  • ROを設定したディスクに中身をまんまコピーして増やせる
    • 負荷分散(その性能はユニオンマウントするソフトにもよるだろうが)できる
    • もし壊れればコピペするだけで良いので管理が楽

ということなのだろうか…

権限の種類

英字10字の2つ目〜9つ目が該当する,別名ファイルモード(英語ではそう書かれる)

まとめると

  • 9つの文字は3つの欄で構成
    • owner,製作者・所有者
    • group,特定の利用者群
      • macOSではstaffadminwheelrootのどれか
      • デフォルトではownerprimary groupが優先される
      • どのユーザもprimary groupstaffになっている,UNIX系ならidと打って出てきたgidprimary groupを指すとか
    • other,それ以外の第三者
      • macOSではeveryoneと表記されているが,ここではotherで統一する
  • 1つの欄は3つの文字で構成
    • readable
      • ファイルなら読込可能
      • ディレクトリなら子要素の一覧が可能
      • rならOK,-ならNG
      • 数字では4
    • writable
      • ファイルなら書込可能
      • ディレクトリなら子要素の作成・削除・属性の編集が可能
      • wならOK,-ならNG
      • 数字では2
    • executable/searchable
      • ファイルなら実行可能
      • ディレクトリなら子要素の中身の利用・移動が可能
      • xならOK,-ならNG
      • 数字では1
  • それぞれの欄は数字の和算で表現することができる +124 はどう足しても重複が起きないので

オプション

上記に加えてsetuidsetgidstickyが各欄の3つ目に出現する時がある,ファイルシステムによってはその表示が異なるらしいのだが,macOSにおいては以下となる

owner group other
setuid s(1) or S(2) - -
setgid - s(3) or S(4) -
sticky - - t(5) or T(6)

これを各種の権限に当てはめて整理するとと以下となる

(1) (2) (3) (4) (5) (6)
file 実行可能+setuid 実行不可能+setuid 実行可能+setgid
↑Linuxだと効果がないらしい
実行不可能+setgid↑Linuxだと効果がないらしい - -
directory - - Linuxとは違いこっちは効果がない
あっちは子要素を所有するgroupを同期させられるらしい
Linuxとは違いこっちは効果がない
あっちは子要素の所有するgroupを同期させられるとか
利用可能+sticky 利用不可能+sticky

setuid

owner以外でもowner(の持つuid)の権限でファイルを実行できる,使い方を間違えたり脆弱性があったりすると危険
数字では4

setgid

ownerの所属するgroup以外でもownerの所属するgroup(の持つuid)の権限でファイルを実行できる←よくわからないけどmanページに本当にこう書いてあるからしょうがないもん!怖くて使えないけど(groupの操作に慣れてないだけ)
数字では2

sticky

このディレクトリの子要素であるファイル・ディレクトリは共にowner以外の削除と属性変更が拒否される,/tmpとか
数字では1

拡張属性

英字10字の後に@がある場合はOSによる拡張属性が設定されている,例えば~(ユーザのホームディレクトリ)は

    com.apple.FinderInfo      32B 
 0: group:everyone deny delete

と表示されるはず,このように単にrwxだけでは指定できない特定の操作(この場合は削除)をバインドしてる場合が多そう

拡張ACL

英字10字の後に+がある場合はOSによる拡張セキュリティが設定されている…らしいのだが,未だに見たことがない,これはアクセスコントロールリスト(ACL)とも呼ばれる

その他の情報

以上で基本的な管理については事足りると思うのだが,ls -l@FTOaehipsで全て表示されるものは何かをそれぞれメモしておく

[iノード番号] [ブロックサイズ] [権限+拡張属性+拡張ACL] [リンク数] [owner] [group] [ファイルフラグ] [ファイルサイズ] [最終更新日] [名前]

iノード番号

UNIX系システムは属性情報を管理・追跡するために固定番号を使用している.
該当のオブジェクトがファイルシステム上から消されたりしない限りは変わらない.

ブロックサイズ

UNIX系システムはデータを書き込む際にこの単位を利用している.
macOSにおいては,最低でもオブジェクトに対して1つあたり4KB(4KiByte)=4096B(4096Byte)が確保され,これが8blockに相当することから1blockあたり512Byteであるとわかる.この512Byteこそが一般的なSSD・HDD・RAMで用いられる物理的なブロックに相当するが,macOSのAPFSは4KiByte=8blockごとで使用するため(これをアロケーションと呼ぶ),要は4KiByte(これをアロケーションユニットサイズと呼ぶ)に満たないファイルを大量に生成することは,ストレージ節約の観点から見る限りでは無駄だということがわかる.一応ファイルサイズが0ならブロックサイズも0なので安心できる.(まぁiノード番号を浪費するかもしれないけど今時の64bitならそう困らないはず)

普通のディレクトリ

ディレクトリエントリの情報を持つのでファイルサイズは0ではない…のだがブロックサイズは0である.どこかしら実体があると思われるが情報が見つからない,iノード番号と似たような場所にあると見ているがAPFSの実装の肝になってそうなので割と社外秘(部外秘)な情報ではないかと予想している.

名前付きパイプ

ファイルサイズが0,すなわちブロックサイズも0である.

シンボリックリンク

パスの情報を持つのでファイルサイズは0ではない…のだがブロックサイズはなぜか0である,普通のディレクトリと同じ事情があるのではないかと予想している.

ハードリンク

同じiノード番号を参照するので実体としてディスクを消費することはないが,それも考慮した上で丁寧にカウントしないと実際のディスク消費量から外れた値を得る羽目になる.表示されるファイルサイズとブロックサイズも,iノード番号が同じであれば同じである.

リンク数

あるiノード番号を持つオブジェクトに対するハードリンクの数,実は./(自己参照)も../(親参照)もハードリンクの扱いであるため,子ディレクトリを増やすと親ディレクトリのリンク数は必ず1増える.シンボリックリンクはiノード番号が異なるためにリンク数にはカウントされない.
ちなみにシンボリックリンクに対してハードリンクを生成しようとすると,シンボリックリンクが参照した実体のiノード番号を持つハードリンクが生成される,これは何重にシンボリックリンクを重ねても変わらない.つまりシンボリックリンクのiノード番号はシンボリックリンクについて固有であり,シンボリックリンクを重ねる場合はそれぞれにiノード番号が与えられている.

ファイルフラグ

通常の権限の種類とはまた異なるもので,アプリケーションも含めた様々な表示や動作について簡単に縛ることができる.
例えばmacOSのSIPが有効な状態ではrestrictedフラグが付いたものは削除や変更ができなくなる,/bin/zshなんかそう.

ファイルサイズ

普通なら単位はバイト,-hで単位も表示される.

最終更新日

-tUすると作成created時間,-tcすると変更changed時間,-tuすると接触access時間になる,使い分けよう.

権限の管理

chmod [1桁目][2桁目][3桁目][4桁目] [ファイル名orディレクトリ名]で数字を並べれば良い,前述したリストとパターンを記憶できたら以下を設定する
ちなみにアルファベットを並べての設定はできない,数字で考える習慣を身につけよう

オプション

  • -v
    • 変更結果を出力してくれる,おすすめ
  • -h
    • シンボリックリンクを追跡せずシンボリックリンクそのものの権限のみを変更する,
    • つまりデフォルトでは勝手に追跡して変更するらしい,うわこっわ…気をつけよ…
    • なおハードリンクの場合はこれの有無に関わらず問答無用で変更する,これは同じiモード番号だからしょうがないね
  • -R
    • ディレクトリ構造に対して再帰処理を行う
    • ワイルドカードかなんかを使って../を含めちゃうと…どうなると思う?(暗黒微笑)
  • -P-H-L
    • -Rを指定した時に発動
    • -Pは全てのシンボリックリンクを除外する,これがデフォルト
    • -Hは引数で与えられたシンボリックリンクのみを対象とする
    • -Lは手当たり次第に全てのシンボリックリンクを対象とする

私は保険のために常に-vhしておきたい,ログも残るしシンボリックリンク先を破壊してしまうのは非常によくない気がする

1桁目

オプション設定ができる
それぞれの欄で実行可能かどうかを設定するのは後の3桁で出来るのでここでは考えなくても良い
特に需要がなければ意図的に0を入れてもいいし入れなくても(省略しても)いい

2桁目

owner欄の設定をする

3桁目

group欄の設定をする

4桁目

other欄の設定をする

所有の管理

chownchgrpは現時点ではここでは扱わない(追記こそするかもしれないが),本題から逸れすぎるし私がmacOSで多用する機会もそうそうなさそうなので許してくれ

シェルスクリプト

1行目で#/bin/zshで実行シェルを指定してから(シェバンと言う)スクリプトを書く,所用のディレクトリにパスを通したら

touch zshTest1
ls -l@FTOaehips testZsh1
# => <inodeID> <BlockSize> -rw-r--r--  1 <UserName>  Staff  -   <FileSize> <Last Updated Time> testZsh1
vi zshTese1
zshTest1
#!/bin/zsh
#testZsh1

echo "this is test script 1"

しかしこの権限ではzshを通して実行できる(自分が権限を持つzshtestZsh1を読み込んで実行しただけなので)ものの単品では実行できない(明らかに-rw-r--r--なので),これは面倒というか不都合である

testZsh1 
# => zsh: permission denied: testZsh1
zsh testZsh1 
# => this is test script 1

なので権限を変更すれば良い,これで単品で実行できるようになる

chmod 0744 testZsh1 
testZsh1           
# => this is test script 1
ls -l@FTOaehips testZsh1
# => <inodeID> <BlockSize> -rwxr--r--  1 <UserName>  Staff  -   <FileSize> <Last Updated Time> testZsh1

なお,owner欄の実行権限の有無によってシェルスクリプトファイルの表示がFinder上で変化する今まで気づかなかった

おまけ

man lsDESCRIPTIONを抜き出した

DESCRIPTION
     For each operand that names a file of a type other than directory, ls
     displays its name as well as any requested, associated information.  For
     each operand that names a file of type directory, ls displays the names of
     files contained within that directory, as well as any requested, associated
     information.

     If no operands are given, the contents of the current directory are
     displayed.  If more than one operand is given, non-directory operands are
     displayed first; directory and non-directory operands are sorted separately
     and in lexicographical order.

     The following options are available:

     -@      Display extended attribute keys and sizes in long (-l) output.

     -A      Include directory entries whose names begin with a dot (‘.’) except
         for . and ...  Automatically set for the super-user unless -I is
         specified.

     -B      Force printing of non-printable characters (as defined by ctype(3)
         and current locale settings) in file names as \xxx, where xxx is
         the numeric value of the character in octal.  This option is not
         defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -C      Force multi-column output; this is the default when output is to a
         terminal.

     -D format
         When printing in the long (-l) format, use format to format the
         date and time output.  The argument format is a string used by
         strftime(3).  Depending on the choice of format string, this may
         result in a different number of columns in the output.  This option
         overrides the -T option.  This option is not defined in IEEE Std
         1003.1-2008 (“POSIX.1”).

     -F      Display a slash (‘/’) immediately after each pathname that is a
         directory, an asterisk (‘*’) after each that is executable, an at
         sign (‘@’) after each symbolic link, an equals sign (‘=’) after
         each socket, a percent sign (‘%’) after each whiteout, and a
         vertical bar (‘|’) after each that is a FIFO.

     -G      Enable colorized output.  This option is equivalent to defining
         CLICOLOR or COLORTERM in the environment and setting --color=auto.
         (See below.)  This functionality can be compiled out by removing
         the definition of COLORLS.  This option is not defined in IEEE Std
         1003.1-2008 (“POSIX.1”).

     -H      Symbolic links on the command line are followed.  This option is
         assumed if none of the -F, -d, or -l options are specified.

     -I      Prevent -A from being automatically set for the super-user.  This
         option is not defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -L      Follow all symbolic links to final target and list the file or
         directory the link references rather than the link itself.  This
         option cancels the -P option.

     -O      Include the file flags in a long (-l) output.  This option is
         incompatible with IEEE Std 1003.1-2008 (“POSIX.1”).  See chflags(1)
         for a list of file flags and their meanings.

     -P      If argument is a symbolic link, list the link itself rather than
         the object the link references.  This option cancels the -H and -L
         options.

     -R      Recursively list subdirectories encountered.

     -S      Sort by size (largest file first) before sorting the operands in
         lexicographical order.

     -T      When printing in the long (-l) format, display complete time
         information for the file, including month, day, hour, minute,
         second, and year.  The -D option gives even more control over the
         output format.  This option is not defined in IEEE Std 1003.1-2008
         (“POSIX.1”).

     -U      Use time when file was created for sorting or printing.  This
         option is not defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -W      Display whiteouts when scanning directories.  This option is not
         defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -a      Include directory entries whose names begin with a dot (‘.’).

     -b      As -B, but use C escape codes whenever possible.  This option is
         not defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -c      Use time when file status was last changed for sorting or printing.

     --color=when
         Output colored escape sequences based on when, which may be set to
         either always, auto, or never.

         always will make ls always output color.  If TERM is unset or set
         to an invalid terminal, then ls will fall back to explicit ANSI
         escape sequences without the help of termcap(5).  always is the
         default if --color is specified without an argument.

         auto will make ls output escape sequences based on termcap(5), but
         only if stdout is a tty and either the -G flag is specified or the
         COLORTERM environment variable is set and not empty.

         never will disable color regardless of environment variables.
         never is the default when neither --color nor -G is specified.

         For compatibility with GNU coreutils, ls supports yes or force as
         equivalent to always, no or none as equivalent to never, and tty or
         if-tty as equivalent to auto.

     -d      Directories are listed as plain files (not searched recursively).

     -e      Print the Access Control List (ACL) associated with the file, if
         present, in long (-l) output.

     -f      Output is not sorted.  This option turns on -a.  It also negates
         the effect of the -r, -S and -t options.  As allowed by IEEE Std
         1003.1-2008 (“POSIX.1”), this option has no effect on the -d, -l,
         -R and -s options.

     -g      This option has no effect.  It is only available for compatibility
         with 4.3BSD, where it was used to display the group name in the
         long (-l) format output.  This option is incompatible with IEEE Std
         1003.1-2008 (“POSIX.1”).

     -h      When used with the -l option, use unit suffixes: Byte, Kilobyte,
         Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the
         number of digits to four or fewer using base 2 for sizes.  This
         option is not defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -i      For each file, print the file's file serial number (inode number).

     -k      This has the same effect as setting environment variable BLOCKSIZE
         to 1024, except that it also nullifies any -h options to its left.

     -l      (The lowercase letter “ell”.) List files in the long format, as
         described in the The Long Format subsection below.

     -m      Stream output format; list files across the page, separated by
         commas.

     -n      Display user and group IDs numerically rather than converting to a
         user or group name in a long (-l) output.  This option turns on the
         -l option.

     -o      List in long format, but omit the group id.

     -p      Write a slash (‘/’) after each filename if that file is a
         directory.

     -q      Force printing of non-graphic characters in file names as the
         character ‘?’; this is the default when output is to a terminal.

     -r      Reverse the order of the sort.

     -s      Display the number of blocks used in the file system by each file.
         Block sizes and directory totals are handled as described in The
         Long Format subsection below, except (if the long format is not
         also requested) the directory totals are not output when the output
         is in a single column, even if multi-column output is requested.
         (-l) format, display complete time information for the file,
         including month, day, hour, minute, second, and year.  The -D
         option gives even more control over the output format.  This option
         is not defined in IEEE Std 1003.1-2008 (“POSIX.1”).

     -t      Sort by descending time modified (most recently modified first).
         If two files have the same modification timestamp, sort their names
         in ascending lexicographical order.  The -r option reverses both of
         these sort orders.

         Note that these sort orders are contradictory: the time sequence is
         in descending order, the lexicographical sort is in ascending
         order.  This behavior is mandated by IEEE Std 1003.2 (“POSIX.2”).
         This feature can cause problems listing files stored with
         sequential names on FAT file systems, such as from digital cameras,
         where it is possible to have more than one image with the same
         timestamp.  In such a case, the photos cannot be listed in the
         sequence in which they were taken.  To ensure the same sort order
         for time and for lexicographical sorting, set the environment
         variable LS_SAMESORT or use the -y option.  This causes ls to
         reverse the lexicographical sort order when sorting files with the
         same modification timestamp.

     -u      Use time of last access, instead of time of last modification of
         the file for sorting (-t) or long printing (-l).

     -v      Force unedited printing of non-graphic characters; this is the
         default when output is not to a terminal.

     -w      Force raw printing of non-printable characters.  This is the
         default when output is not to a terminal.  This option is not
         defined in IEEE Std 1003.1-2001 (“POSIX.1”).

     -x      The same as -C, except that the multi-column output is produced
         with entries sorted across, rather than down, the columns.

     -y      When the -t option is set, sort the alphabetical output in the same
         order as the time output.  This has the same effect as setting
         LS_SAMESORT.  See the description of the -t option for more
         details.  This option is not defined in IEEE Std 1003.1-2001
         (“POSIX.1”).

     -%      Distinguish dataless files and directories with a '%' character in
         long

     -1      (The numeric digit “one”.) Force output to be one entry per line.
         This is the default when output is not to a terminal.  (-l) output,
         and don't materialize dataless directories when listing them.

     -,      (Comma) When the -l option is set, print file sizes grouped and
         separated by thousands using the non-monetary separator returned by
         localeconv(3), typically a comma or period.  If no locale is set,
         or the locale does not have a non-monetary separator, this option
         has no effect.  This option is not defined in IEEE Std 1003.1-2001
         (“POSIX.1”).

     The -1, -C, -x, and -l options all override each other; the last one
     specified determines the format used.

     The -c, -u, and -U options all override each other; the last one specified
     determines the file time used.

     The -S and -t options override each other; the last one specified
     determines the sort order used.

     The -B, -b, -w, and -q options all override each other; the last one
     specified determines the format used for non-printable characters.

     The -H, -L and -P options all override each other (either partially or
     fully); they are applied in the order specified.

     By default, ls lists one entry per line to standard output; the exceptions
     are to terminals or when the -C or -x options are specified.

     File information is displayed with one or more ⟨blank⟩s separating the
     information associated with the -i, -s, and -l options.

DESCRIPTION
     In legacy mode, the -f option does not turn on the -a option and the -g,
     -n, and -o options do not turn on the -l option.

     Also, the -o option causes the file flags to be included in a long (-l)
     output; there is no -O option.

     When -H is specified (and not overridden by -L or -P) and a file argument
     is a symlink that resolves to a non-directory file, the output will reflect
     the nature of the link, rather than that of the file.  In legacy operation,
     the output will describe the file.

     For more information about legacy mode, see compat(5).



man chmodMODEを抜き出した

MODES
     Modes may be absolute or symbolic.  An absolute mode is an octal number
     constructed from the sum of one or more of the following values:

       4000    (the setuid bit).  Executable files with this bit set will
           run with effective uid set to the uid of the file owner.
           Directories with this bit set will force all files and sub-
           directories created in them to be owned by the directory
           owner and not by the uid of the creating process, if the
           underlying file system supports this feature: see chmod(2)
           and the suiddir option to mount(8).
       2000    (the setgid bit).  Executable files with this bit set will
           run with effective gid set to the gid of the file owner.
       1000    (the sticky bit).  See chmod(2) and sticky(7).
       0400    Allow read by owner.
       0200    Allow write by owner.
       0100    For files, allow execution by owner.  For directories, allow
           the owner to search in the directory.
       0040    Allow read by group members.
       0020    Allow write by group members.
       0010    For files, allow execution by group members.  For
           directories, allow group members to search in the directory.
       0004    Allow read by others.
       0002    Allow write by others.
       0001    For files, allow execution by others.  For directories allow
           others to search in the directory.

     For example, the absolute mode that permits read, write and execute by the
     owner, read and execute by group members, read and execute by others, and
     no set-uid or set-gid behaviour is 755 (400+200+100+040+010+004+001).

     The symbolic mode is described by the following grammar:

       mode     ::= clause [, clause ...]
       clause   ::= [who ...] [action ...] action
       action   ::= op [perm ...]
       who      ::= a | u | g | o
       op       ::= + | - | =
       perm     ::= r | s | t | w | x | X | u | g | o

     The who symbols ``u'', ``g'', and ``o'' specify the user, group, and other
     parts of the mode bits, respectively.  The who symbol ``a'' is equivalent
     to ``ugo''.

     The perm symbols represent the portions of the mode bits as follows:

       r       The read bits.
       s       The set-user-ID-on-execution and set-group-ID-on-execution
           bits.
       t       The sticky bit.
       w       The write bits.
       x       The execute/search bits.
       X       The execute/search bits if the file is a directory or any of
           the execute/search bits are set in the original (unmodified)
           mode.  Operations with the perm symbol ``X'' are only
           meaningful in conjunction with the op symbol ``+'', and are
           ignored in all other cases.
       u       The user permission bits in the original mode of the file.
       g       The group permission bits in the original mode of the file.
       o       The other permission bits in the original mode of the file.

     The op symbols represent the operation performed, as follows:

     +     If no value is supplied for perm, the ``+'' operation has no effect.
       If no value is supplied for who, each permission bit specified in
       perm, for which the corresponding bit in the file mode creation mask
       (see umask(2)) is clear, is set.  Otherwise, the mode bits
       represented by the specified who and perm values are set.

     -     If no value is supplied for perm, the ``-'' operation has no effect.
       If no value is supplied for who, each permission bit specified in
       perm, for which the corresponding bit in the file mode creation mask
       is set, is cleared.  Otherwise, the mode bits represented by the
       specified who and perm values are cleared.

     =     The mode bits specified by the who value are cleared, or, if no who
       value is specified, the owner, group and other mode bits are cleared.
       Then, if no value is supplied for who, each permission bit specified
       in perm, for which the corresponding bit in the file mode creation
       mask is clear, is set.  Otherwise, the mode bits represented by the
       specified who and perm values are set.

     Each clause specifies one or more operations to be performed on the mode
     bits, and each operation is applied to the mode bits in the order
     specified.

     Operations upon the other permissions only (specified by the symbol ``o''
     by itself), in combination with the perm symbols ``s'' or ``t'', are
     ignored.

     The ``w'' permission on directories will permit file creation, relocation,
     and copy into that directory.  Files created within the directory itself
     will inherit its group ID.


MODES
     644       make a file readable by anyone and writable by the owner
           only.

     go-w      deny write permission to group and others.

     =rw,+X    set the read and write permissions to the usual defaults, but
           retain any execute permissions that are currently set.

     +X        make a directory or file searchable/executable by everyone if
           it is already searchable/executable by anyone.

     755
     u=rwx,go=rx
     u=rwx,go=u-w  make a file readable/executable by everyone and writable by
           the owner only.

     go=       clear all mode bits for group and others.

     g=u-w     set the group bits equal to the user bits, but clear the
           group write bit.



0
1
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
0
1