關於struct stat

在Unix/Linux中,stat能夠得到一個文件的狀態信息,而這些信息都放到一個結構體中struct stat,其中的成員以下 node

struct stat { ui

       mode_t    st_mode;      //文件對應的模式,文件,目錄等 command

       ino_t     st_ino;      //inode節點號 im

       dev_t     st_dev;       //設備號碼 文件

       dev_t     st_rdev;      //特殊設備號碼 時間

       nlink_t   st_nlink;     //文件的鏈接數 co

       uid_t     st_uid;       //文件全部者 block

       gid_t     st_gid;       //文件全部者對應的組 time

       off_t     st_size;      //普通文件,對應的文件字節數 path

       time_t    st_atime;     //文件最後被訪問的時間

       time_t    st_mtime;     //文件內容最後被修改的時間

       time_t    st_ctime;     //文件狀態改變時間

       blksize_t st_blksize;   //文件內容對應的塊大小

       blkcnt_t  st_blocks;    //偉建內容對應的塊數量

     };

平時咱們用到的不少的命令都是從這些底層的信息來運做的。

chmod就是該表的st_mode,還有相似的chown chgrp,ln命令也與st_link有關,find命令 如 find path -atime -ctime  -mtime 時間 [-exec command {} \;]都是根據st_atime st_mtime st_ctime 來的。我猜測應該 st_size = st_blksize* st_blocks 的(具體我也沒有驗證)

相關文章
相關標籤/搜索