改變檔案權限

  1. chmod 輔助說明
    [root@kvm8 ~]# chmod --help
    Usage: chmod [OPTION]... MODE[,MODE]... FILE...
      or:  chmod [OPTION]... OCTAL-MODE FILE...
      or:  chmod [OPTION]... --reference=RFILE FILE...
    Change the mode of each FILE to MODE.
    With --reference, change the mode of each FILE to that of RFILE.
    
      -c, --changes          like verbose but report only when a change is made
      -f, --silent, --quiet  suppress most error messages
      -v, --verbose          output a diagnostic for every file processed
          --dereference      affect the referent of each symbolic link,
                               rather than the symbolic link itself
      -h, --no-dereference   affect each symbolic link, rather than the referent
          --no-preserve-root  do not treat '/' specially (the default)
          --preserve-root    fail to operate recursively on '/'
          --reference=RFILE  use RFILE's mode instead of specifying MODE values.
                             RFILE is always dereferenced if a symbolic link.
      -R, --recursive        change files and directories recursively
    
    The following options modify how a hierarchy is traversed when the -R
    option is also specified.  If more than one is specified, only the final
    one takes effect. '-H' is the default.
    
      -H                     if a command line argument is a symbolic link
                             to a directory, traverse it
      -L                     traverse every symbolic link to a directory
                             encountered
      -P                     do not traverse any symbolic links
    
          --help        display this help and exit
          --version     output version information and exit
    
    Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=][0-7]+'.
    
    GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
    Full documentation <https://www.gnu.org/software/coreutils/chmod>
    or available locally via: info '(coreutils) chmod invocation'
    
  2. chmod 命令設定
    chmod [ -R ] xyz 檔案或目錄
    chmod [ -R ] u = r 檔案或目錄
                 g + w 檔案或目錄
                 o - x 檔案或目錄
                 a     檔案或目錄
    chmod u=rwx,go=rx 檔案或目錄
    chmod a-x 檔案或目錄
    
    1. xyz 為三組 rwx 屬性數值之加總。
      r : 4
      w : 2
      x : 1
    2. -rwxr-xr-- 之屬性數值為 754。
    3. 符號類型
      u : user
      g : group
      o : other
      a : all
      + : 加入
      - : 除去
      = : 設定
  3. 例題:若從光碟複製某一目錄 abc (包含次目錄之所有檔案)至硬碟,則目前使用者雖為檔案擁有者,但卻無法修改該檔案,請問如何以簡單的方式,讓使用者可以修改所有檔案?
    chmod u+w -R abc