chmod和fchmod函數 /chown ,fchown,lchown函數

來源:互聯網
上載者:User

標籤:des   style   blog   os   ar   strong   檔案   sp   div   

這兩個函數使我們可以更改現有檔案的存取權限:

#include <sys/stat.h>int chmod( const char *pathname, mode_t mode );int fchmod( int filedes, mode_t mode );兩個函數傳回值:若成功則返回0,若出錯則返回-1

 

chmod函數在指定的檔案上進行操作,而fchmod函數則對已開啟的檔案進行操作。

為了改變一個檔案的許可權位,進程的有效使用者ID必須等於檔案的所有者ID,或者該進程必須具有超級使用者權限。

參數mode所示常量的某種按位或運算構成的

mode 說明
S_ISUID 
S_ISGID 
S_ISVTX
執行時設定使用者ID 
執行時設定組ID 
儲存本文(粘住位)
S_IRWXU 
     S_IRUSR 
     S_IWUSR 
     S_IXUSR
使用者(所有者)讀、寫和執行 
使用者(所有者)讀 
使用者(所有者)寫 
使用者(所有者)執行
S_IRWXG 
     S_IRGRP 
     S_IWGRP 
     S_IXGRP
組讀、寫和執行 
組讀 
組寫 
組執行
S_IRWXO 
     S_IROTH 
     S_IWOTH 
     S_IXOTH
其他讀、寫和執行 
其他讀 
其他寫 
其他執行

 

 

 

 

 

 

 

 

 

 

 

 

 

 

chown函數可用於變更檔的使用者ID和組ID:

#include <unistd.h>int chown( const char *pathname, uid_t owner, gid_t group );int fchown( int filedes, uid_t owner, gid_t group );int lchown( const char *pathname, uid_t owner, gid_t group );                   三個函數的傳回值:若成功則返回0,若出錯則返回-1

 

chmod和fchmod函數 /chown ,fchown,lchown函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.