The stat command is really useful to gather information from file, directory and file system.
The basic usage of stat is:
~#stat /etc/passwd File: `/etc/passwd' Size: 999 Blocks: 8 IO Block: 4096 regular file Device: ca00h/51712d Inode: 845 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2011-05-26 12:14:41.000000000 +0200 Modify: 2011-05-26 12:14:41.000000000 +0200 Change: 2011-05-26 12:14:41.000000000 +0200
So, without options you can have the following information
File : Size in Bytes
Blocks : Number of blocks used
IO Block : Size in bytes of every block.
Device : The identifier number of your storage device (harddrive, etc.)
Inode : The inode number that the file or directory is linked to.
Access/Modify and change Times : Note that the timestamps also include which time zone that accesses or modifications took place in. in this example +0200
The following are some of the flags and arguments that can be used for the stat command:
-f, --filesystem display filesystem status instead of file status -c --format=FORMAT use the specified FORMAT instead of the default -L, --dereference follow links -Z, --context print the security context
File system status
~# stat -f / File: "/" ID: 64d0ef29968c53b0 Namelen: 255 Type: ext2/ext3 Block size: 4096 Fundamental block size: 4096 Blocks: Total: 4012826 Free: 3440842 Available: 3275692 Inodes: Total: 3701376 Free: 3668155
As you can see the output it’s a bit different with the -f flag you get information on the Type of FS and on the status of the blocks and of inodes (total/free). The -f can be used also with a file in that case the information will be the one of the FS that contains it (i.g.
stat -f /etc/passwd
With the -c options you can control which information display in the output of the command stat.
For example to print the permissions of all files in letters and octal you can use:
~# stat -c '%A %a %n' * -rw-r--r-- 644 adduser.conf -rw-r--r-- 644 adjtime -rw-r--r-- 644 aliases drwxr-xr-x 755 alternatives drwxr-xr-x 755 apache2 drwxr-xr-x 755 apt -rw-r----- 640 at.deny -rw-r--r-- 644 bash.bashrc -rw-r--r-- 644 bash_completion drwxr-xr-x 755 bash_completion.d -rw-r--r-- 644 bindresvport.blackli ....