The Stat Utility

The program was born when I had to use information from the data structure returned by the system call stat(). I thought it'd be nice if I had a utility that would simply dump the data found there. So I sat down and hastily coded most of this utility. It was later refined to work on different platforms and to print even more information.

The only thing it doesn't do as of now is following symbolic links.

Compatibility

Anything that has to with system calls is by definition non-portable, even it is a standard C function call. I have tried to work around these problems, and it now runs on a variety of unixes, including It has not been tried so far on DOS, but because of no user access handling, you wouldn't need it there.

Sample Output

Here are two samples:

stat ~/c/stat.c

File information for /usr/usersb2/w93/fp/c/stat.c
           Filesystem ID : Major 00 Minor 08
              File inode : 107446
               File mode : FILE -rw-r--r--
             Your rights : READ WRITE DELETE
         Number of Links : 1
                 User ID : 1341 (fp)
                Group ID : 1022 (w93)
               File Size : 7311
        Last File access : Tue Dec  6 18:17:33 1994
        ... modification : Fri Dec  2 15:07:57 1994
           File creation : Wed Dec 14 10:02:23 1994

The first line tells you the unique identifier of the filesystem the file is on. Together with the second line, the file's inode, it uniquely identifies each file on a system. The third line mentions that you're dealing with a plain file, and prints the file's mode. The program also evaluates your own user and group IDs and tells you about your rights on the file. Since I am the owner of my own file, I may read from it, write to it and delete it.
The file has a link count of one, and therefore doesn't exist under another name (when unlinking this file, the count becomes zero and so the file is deleted), although symlinks to this file may exist. The next two lines show the user and group IDs both numerically, and, if available, also as text. The file size is 7311 bytes. The last three lines tell about the last access, modification and creation dates and times.
BTW, what stat() does doesn't count as file access.

stat ~olschew

File information for /usr/usersb2/w93/olschew
           Filesystem ID : Major 00 Minor 08
              File inode : 103392
               File mode : DIRECTORY -rwxr-xr-x
             Your rights : LIST  CHANGE TO
                 User ID : 1541 (olschew)
                Group ID : 1022 (w93)
Here, I've stat'ed another user's home directory (I've cut the date information), and we see that we may indeed list the files in his directory and we may also change to it.

Compiling and Running

As long as you have an ANSI-compatible compiler on a Unix system, you should be fine. Just compile the program using all the default settings. If the compiler finds any errors, mail its output and a description of your system to me. If you have DOS or any other non-multi-user system, forget about the program, you won't need it.

On the command line, it will accept one or more filenames, and it prints information for all these files. If a file is not stat()'able (usually because it doesn't exist or because the parent directory is unreadable), a message and the error code (errno) is printed.

Get the source file, stat.c (7kB)


Frank Pilhofer <fp -AT- fpx.de> Back to the Homepage
Last modified: Fri Mar 31 18:41:21 1995