next up previous contents
Next: The system function Up: Interacting with the Operating Previous: File Test Operators   Contents

The stat function

The file test operators of Section [*] provide useful ``yes/no'' information about files, but when you need to know, say, the exact date a file was accessed or modified, or the owner of the file, you will need something more powerful. Most information of this type could be produced by parsing the output of some operating system command, but a much more efficient way of getting this information is to use the stat function. You pass a valid filename to stat, and it returns an array with thirteen elements, as listed in Table [*].


Table: Elements returned by the stat function
Element    
Number Name Meaning
0 dev device number of filesystem
1 ino inode number
2 mode file mode (type and permissions)
3 nlink number of (hard) links to the file
4 uid numeric user ID of file's owner
5 gid numeric group ID of file's owner
6 rdev the device identifier (special files only)
7 size total size of file, in bytes
8 atime last access time in seconds since Jan 1, 1970
9 mtime last modify time in seconds since Jan 1, 1970
10 ctime inode change time in seconds since Jan 1, 1970
11 blksize preferred block size for file system I/O
12 blocks actual number of blocks allocated


Many times you will only need to extract a single value from the stat function. You can use the technique outlined in Section 4.3 to access only the pieces you want. Like the file test operators (Section [*]), the underscore can also be used to refer to the most recently queried file.


next up previous contents
Next: The system function Up: Interacting with the Operating Previous: File Test Operators   Contents
Phil Spector 2002-10-18