Home » 2015 » June » 3 » STAT command : check file or filesystem statistics

7:36 PM
STAT command : check file or filesystem statistics

STAT command : It is used to show the statistics of a file or filesystem in Linux

Format       stat [OPTION] FILE/FILESYSTEM...


DESCRIPTION
       It shows the statistics of a file or file system with the informations like block size, inode number, acces/modifcation time, permssions, type of file/filesystem etc.

       -f, --file-system
              it display file system status instead of file status

       -c  --format=FORMAT
              use the specified FORMAT instead of the default; output a newline after each use of FORMAT

       --printf=FORMAT
              like --format, but interpret backslash escapes, and do not output a mandatory trailing newline.  If you want a newline, include \n in FORMAT.

       -t, --terse
              print the information in terse form


Examples:

1. Display the statistics of root directory "/"

# stat /
  File: `/'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: ca03h/51715d    Inode: 2           Links: 25
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-06-02 14:07:49.000000000 +0200
Modify: 2015-01-02 10:48:46.000000000 +0100
Change: 2015-05-27 17:12:24.000000000 +0200

Here the fields which are shown in the output for a file statistics

Size: size of file in bytes

Blocks: no of blocks occupied

Type of file: directory/file

Acces time: last access timestamp

Modify: time stamp of last modification

Change:time stamp of last changes

Uid: User id of the user

Gid : Group id of the group


And below are the fields for filesystem statistics:

ID : file system id in hexadecimal

Type : Type of filesystem Eg. nfs, ext2/3, tmpfs, sysfs, proc etc.

Free/Available/Total: available/free/total memory

Block size: block size

Inodes: number of indoes free/total

2. Display the statistics of file system "/"
 

# stat -f /
  File: "/"
    ID: bb8baf93364d453a Namelen: 255     Type: ext2/ext3
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 12936887   Free: 6659291    Available: 6002133
Inodes: Total: 3286752    Free: 2593653

3. Check the statistics of a NFS Filesystem "/nfs/app/mint
 

# stat -f /nfs/app/mint
  File: "/nfs/app/mint"
    ID: 0        Namelen: 255     Type: nfs
Block size: 8192       Fundamental block size: 8192
Blocks: Total: 6553600    Free: 1944276    Available: 1944276
Inodes: Total: 11138878   Free: 10783212


4. Check the status a file "sent"

# stat sent
  File: `sent'
  Size: 430990          Blocks: 856        IO Block: 4096   regular file
Device: ca03h/51715d    Inode: 58885       Links: 1
Access: (0600/-rw-------)  Uid: (386399/ shanky)   Gid: (86441/shangroup)
Access: 2015-02-10 16:11:13.000000000 +0100
Modify: 2015-02-10 16:11:13.000000000 +0100
Change: 2015-02-10 16:11:13.000000000 +0100

5. Print the status of a file in terse form

See the comparision of below two outputs:

# stat -t abc.pl
abc.pl
49 8 81b0 386399 86441 ca03 59541 1 0 0 1386321547 1386321542 1386321542 4096
# stat abc.pl
  File: `abc.pl'
  Size:
49              Blocks:          IO Block: 4096   regular file
Device: ca03h/51715d    Inode:
59541       Links: 1
Access: (0660/-rw-rw----)  Uid: (
386399/ shanky)   Gid: (86441/shangroup)
Access: 2013-12-06 10:19:07.000000000 +0100
Modify: 2013-12-06 10:19:02.000000000 +0100
Change: 2013-12-06 10:19:02.000000000 +0100


6. We can print the statistics in our desired format also using --format option. See below examples:

  • Print access permissions of a file in octal format:
     

# stat --format %a testfile
660

  • Print access permissions of a file in human readable format:
     

# stat --format %A testfile
-rw-rw----

7. Show the types of all the filesystems in root folder

# stat -f --format %T *|sort -u
ext2/ext3
proc
sysfs
tmpfs


Following are the valid format sequences for files (without --file-system):

       %a     Access rights in octal

       %A     Access rights in human readable form

       %b     Number of blocks allocated (see %B)

       %B     The size in bytes of each block reported by %b

       %C     SELinux security context string

       %d     Device number in decimal

       %D     Device number in hex

       %f     Raw mode in hex

       %F     File type

       %g     Group ID of owner

       %G     Group name of owner

       %h     Number of hard links

       %i     Inode number

       %n     File name

       %N     Quoted file name with dereference if symbolic link

       %o     I/O block size

       %s     Total size, in bytes

       %t     Major device type in hex

       %T     Minor device type in hex


And for filesystem, below are the formats that can be used:

 Valid format sequences for file systems:

       %a     Free blocks available to non-superuser

       %b     Total data blocks in file system

       %c     Total file nodes in file system

       %d     Free file nodes in file system

       %f     Free blocks in file system

       %C     SELinux security context string

       %i     File System ID in hex

       %l     Maximum length of filenames

       %n     File name

       %s     Block size (for faster transfers)

       %S     Fundamental block size (for block counts)

       %t     Type in hex

       %T     Type in human readable form

 

 
 

Category: Open System-Linux | Views: 1633 | Added by: shanky | Tags: file system statistics, unix, file status, stat command, file, linux, shankysportal, Stat, shankys, filesystem | Rating: 0.0/0

Related blogs


You may also like to see:


[2014-10-04][Open System-Linux]
SYSCTL : A command to configure kernel parameters at runtime in linux
[2014-12-28][Open System-Linux]
Shift command with examples
[2015-08-18][Open System-Linux]
How to open a PDF file or a Postscript file in Linux - Evince Document viewer?
[2014-03-25][Open System-Linux]
Create a new user in Linux system: useradd
[2014-09-20][Open System-Linux]
Export command in Linux

Total comments: 0
ComForm">
avatar