Share on Facebook Share on Twitter Email
Answers.com

Stat

 
Wikipedia: Stat (Unix)

stat() is a Unix system call that returns useful data about a file inode. The semantics of stat() vary between operating systems. As an example, the Unix command ls uses it to retrieve information on (among many others):

  • 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 necessarily the time of file creation. Writing to a file changes its mtime and ctime. A change in file permissions or file ownership can change its ctime. Reading a file changes its atime. File systems mounted with the noatime option do not update the atime on reads, and the relatime option provides for updates only if the previous atime is older than the mtime or ctime. Unlike atime and mtime, ctime cannot be set with utime() (as used e.g. by touch); the only way to set it to an arbitrary value is by changing the system clock.

Contents

lstat()

lstat() is a library function that retrieves the status of a file. It is identical to stat(), except when the file is a symbolic link, in which case information about the link itself is returned instead of the linked-to file.

fstat()

fstat() is a library function that retrieves the status of a file. It is identical to stat() except that the file's identity is passed as a file descriptor instead of as a filename.

stat() functions

The following is a set of declarations from the POSIX library header sys/stat.h typically found on most operating systems.

#include <sys/types.h>
#include <sys/stat.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 */
};

References

External links


Search unanswered questions...
Enter a question here...
Search: All sources Community Q&A Reference topics
Shopping: Stat
Top
 
 
Learn More
statim
stat
stat. (abbreviation)

What is stat infection? Read answer...
What stat is Chisinau in? Read answer...
What are bowling stats? Read answer...

Help us answer these
What city stats with you?
What is a Homework stat?
What is a cockpit stat?

Post a question - any question - to the WikiAnswers community:

 

Copyrights:

Wikipedia. This article is licensed under the Creative Commons Attribution/Share-Alike License. It uses material from the Wikipedia article "Stat (Unix)" Read more