- Stat (Unix)
stat()
is aUnix system call that returns useful data about a fileinode . The semantics ofstat()
vary betweenoperating system s. With theUnix commandls , 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. Writing to a file changes itsmtime
,ctime
, andatime
. A change in file permissions or file ownership changes itsctime
andatime
. Reading a file changes itsatime
. File systems mounted with thenoatime
option do not update the atime on reads, and therelatime
option provides for updates only if the previous atime is older than the mtime or ctime. Unlikeatime
andmtime
,ctime
cannot be set withutime()
(as used e.g. bytouch
); the only way to set it to an arbitrary value is by changing the system clock.lstat()
lstat()
is a library function that retrieves the status of a file. It is identical tostat()
, except when the file is asymbolic 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 tostat()
except that the file's identity is passed as afile descriptor instead of as afilename .tat() functions
The following is a set of declarations from the
POSIX library headersys/stat.h
typically found on most operating systems.#include
#include 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
* [http://linux.die.net/man/2/fstat stat(2) in the Linux Programmer's Manual]
External links
* [http://www.hep.wisc.edu/~pinghc/NoteFileSystemInfo.htm An example showing how to use stat()]
* [http://perldoc.perl.org/functions/stat.html stat() in Perl]
* [http://www.php.net/manual/en/function.stat.php stat() in PHP]
* [http://kerneltrap.org/node/14148 atime and relatime]
Wikimedia Foundation. 2010.