stat (Unix)

From Wikipedia, the free encyclopedia

Jump to: navigation, search


stat() is a Unix system call that returns useful data about an inode. The semantics of stat() vary between operating systems. With Unix command ls, one can gather information about

  • mtime: time of last modification (ls -l),
  • ctime: time of last status change (ls -lc) and
  • atime: time of last access (ls -lu).

Note, that ctime is not the time of file creation. Overwriting a file changes mtime, ctime as well as atime. A change in file permissions or file ownership changes ctime and atime. Reading a file changes atime.

Contents

[edit] lstat()

lstat() is a programing function to get the status of a file, through a Unix system call. lstat() is identical to stat(), except if file is a symbolic link. If so the link itself is stat-ed, not the linked file.

[edit] fstat()

fstat() is a programing function to get the status of a file, through a Unix system call. fstat() is identical to stat() except the file's identity is passed to the function through the integer filedes.

[edit] stat() functions

 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
 int stat(const char *filename, struct stat *buf);
 int lstat(const char *filename, struct stat *buf);
 int fstat(int filedesc, struct stat *buf);
 
 struct stat {
             dev_t     st_dev;     /* ID of device containing file */
             ino_t     st_ino;     /* inode number */
             mode_t    st_mode;    /* protection */
             nlink_t   st_nlink;   /* number of hard links */
             uid_t     st_uid;     /* user ID of owner */
             gid_t     st_gid;     /* group ID of owner */
             dev_t     st_rdev;    /* device ID (if special file) */
             off_t     st_size;    /* total size, in bytes */
             blksize_t st_blksize; /* blocksize for filesystem I/O */
             blkcnt_t  st_blocks;  /* number of blocks allocated */
             time_t    st_atime;   /* time of last access */
             time_t    st_mtime;   /* time of last modification */
             time_t    st_ctime;   /* time of last status change */
 };

[edit] External links

[edit] References

Views
Personal tools

Toolbox