Find Out Server Metadata with Stat

Running Linux on a server is a great way to find out about the inner workings of a computer. Linux provides numerous tools to help you learn important system information. In a previous post, I highlighted some of the Linux tools you can use to find out critical information about your server’s hardware. With the “stat” command, you can find out more information than you would probably ever want to know about your files.

To run the stat command, just type “stat” followed by the filename:

stat file1

and the output will look like this:

Size: 16 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1704093 Links: 1
Access: (0700/-rwx------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2010-06-23 14:41:57.025990758 -0400
Modify: 2010-06-23 14:41:02.805997128 -0400
Change: 2010-06-23 14:41:37.617995039 -0400

It will tell you the file size in bytes, blocks, file type, number of links to the file, access permissions, ownership, and the dates and times of access, modification, and change.

To find out information about all the files in a directory, just type:

stat *

The list can get quite long doing this, so if you want to save the stat information to a file, type:

stat * > file-info

That will save all of the metadata to a file called “file-info”, although you can use any filename you choose. In addition to this basic functionality, stat allows you to customize the output: what items are displayed and how they are arranged. For complete documentation, type “man stat” from the command line.