檔案屬性和目錄屬性

2021-10-09 02:34:05 字數 528 閱讀 4496

檔案屬性:使用 stat() 函式可以獲取

int

stat

(const

char

*pathname,

struct stat *statbuf)

;

裡面有乙個重要的結構體 struct stat ,在 man 2 stat 中可以檢視

struct stat 

;

結構體中的 st_mode 用來判斷檔案型別,該檔案型別如何使用,在man 7 inode中可以檢視

開啟目錄 opendir() 函式

讀目錄 readdir() 函式

遍歷目錄 scandir() 函式

其中有目錄項結構體為 struct dirent 在man 2 readdir中可以檢視

struct old_linux_dirent 

;

檔案屬性和管理

檔案基本屬性 使用ll或者ls l命令來顯示乙個檔案的屬性以及檔案所屬的使用者和組。d 目錄 檔案 l 鏈結 b 可隨機儲存裝置 c 串列埠裝置 鍵盤 滑鼠 接下來三個一組代表許可權 更改檔案屬組 chgrp r 屬組名 檔名 加上r該目錄下所有檔案都被改變 更改檔案屬主,也可同時更改檔案屬組 ch...

列出目錄和檔案屬性(linux)

練習命令列常用快捷鍵 tab ctrl l esc ctrl c 檢視根目錄 下有哪些文件或子目錄 以長格式顯示結果,對比 bin usr bin 目錄詳細屬性 列出當前目錄下的所有文件 包括隱藏文件 列出 root 目錄下以 ana開頭的文件,識別文件大小 1.2 步驟 實現此案例需要按照如下步驟...

設定檔案屬性

程式設計時經常需要某些檔案擁有特定的屬性,譬如隱藏屬性。下面介紹乙個實現此功能的函式 setfileattributes。函式原型 函式原型 boolsetfileattributes lpctstr lpfilename,lpfilename的物件指向乙個字串,指定其屬性要設定的檔案的名稱。例如 ...