linux平台檔案目錄作業碼(1/3)

來源:互聯網
上載者:User

1.檔案類型

stat(),fstat()和lstat()函數

fstat功能和stat類似,只是不以檔案的路徑稱作為標識,而是用檔案描述符標識目標檔案,獲得該檔案的有關資訊。lstat形式和功能都與stat類似,但是當目標檔案是符號連結檔案時,lstat返回該符號串連的有關資訊。

格式:

#inlcude <sys/stat.h>

#include <unistd.h>

int stat(const chat *name, struct stat *buf);

int fstat(int filedes, struct stat *buf);

int lstat(const char *file, stuct stat *buf);

與此命名檔案有關的資訊結構放在buf中。成功則函數返回0,否則返回-1。

2.檔案許可權

(1)access

用來檢查指定檔案的屬性,可以檢查檔案愛你是否可讀,可寫,可執行。

格式:

#include <unistd.h>

int access(const char *file, int mode);

成功返回0,失敗返回-1 。

(3)umask

為 進程設定建立檔案的許可掩碼。

格式:

#include <sys/types.h>

#include <sys/stat.h>

mode_t umask(mode_t mode);

返回以前文的檔案方式建立屏蔽字。無錯誤返回。

(4)chmod和 fchmod

改變檔案的操作許可權

格式:

#include <sys/types.h>

#include <sys/stat.h>

chmod[option]mode[,mode...] file;

int chmod(const char  *path, mode_t mode);

int fchmode(int fileds, mode_t mode);

(5)chown,fchown和lchown

首頁 1 2 3 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.