關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • UNIX 權限數值

    Posted on April 15th, 2007 Sam Tang No comments

    在 UNIX like 環境中要改變檔案或目錄的權限,通常會用上代表權限的數值,例如:

    chmod 777 filename

    以上指令是用 chmod 將檔案 filename 的權限改為 777,以下為權限數值的定義:

    用戶      數值      結果
    Owner: 0400 -> 檔案的 owner 只可以讀取檔案。
    Owner: 0200 -> 檔案的 owner 只可以寫入檔案。
    Owner: 0100 -> 檔案的 owner 只可以執行檔案;如果是目錄,則 owner 可以在目錄進行搜索。

    Group: 0040 -> 用戶組的成員只可以讀取檔案。
    Group: 0020 -> 用戶組的成員只可以寫入檔案。
    Group: 0010 -> 用戶組的成員只可以執行檔案;如果是目錄,則 owner 可以在目錄進行搜索。

    Other: 0004 -> 其他用戶只可以讀取檔案。
    Other: 0002 -> 其他用戶只可以寫入檔案。
    Other: 0001 -> 其他用戶只可以執行檔案;如果是目錄,則 owner 可以在目錄進行搜索。

    要知道需要設定權限的數值,只需將以上各數數值相加,例如我想給予 owner 讀/寫/執行的權限,而用戶組用戶及其他用戶只有讀/執行的權限,那麼就是 0400+0200+0100+0040+0010+0004+0001 = 0755。

    整句指令便會是: chmod 755 filename


    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word