Using stat command to display file or filesystem status on Linux system.

 

Using stat command to display file or filesystem status on Linux system.

 

   The example of using Linux stat command on bash shell to display file or filesystem status on Linux Fedora Core machine.

 

Linux command name: stat

 

   The stat command can be use to check the single file status ( like file properties on Windows) or check the filesystem status on Linux machine.  The example below show the step by step on using the stat command to check file status and check filesystem status.

 

Command Description:

   Display file or filesystem status.

Command Type:

   file.

 

[root@fedora ~]# type -t stat

file

[root@fedora ~]# type -p stat

/usr/bin/stat

 

The stat command will gather the information about a file or filesystem status. This command is useful for checking file permission, inode and symbolic link, for example:

 

[root@fedora ~]# stat install.log

File: `install.log'

Size: 61891 Blocks: 144 IO Block: 4096 regular file

Device: 900h/2304d Inode: 910338 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2005-05-05 12:50:11.000000000 +0800

Modify: 2005-05-05 15:44:16.000000000 +0800

Change: 2005-05-05 15:44:16.000000000 +0800

 

The output of this command show size, filetype, permission, user id, group id and so on… for the install.log file.

 

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

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

    --help  display this help and exit

    --version  output version information and exit

 

The step by step example using stat command on Linux Fedora Core machine.

 

Type in ' stat ' on the Linux shell prompt and press [Enter] key to execute the command.

 

[root@fedora ~]# stat

stat: too few arguments

Try `stat --help' for more information.

 

From the result above, the 'stat' command that we issue on the command prompt is not complete.

 

The output of the above command suggest that we try to issue 'stat --help' command to get more information on how to use the stat command.

 

[root@fedora ~]# stat --help

Usage: stat [OPTION] FILE...

Display file or filesystem status.

 

-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

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

--help display this help and exit

--version output version information and exit

 

The valid format sequences for files (without --filesystem):

 

%A Access rights in human readable form

%a Access rights in octal

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

%b Number of blocks allocated (see %B)

%D Device number in hex

%d Device number in decimal

%F File type

%f Raw mode in hex

%G Group name of owner

%g Group ID of owner

%h Number of hard links

%i Inode number

%N Quoted File name with dereference if symbolic link

%n File name

%o IO block size

%s Total size, in bytes

%T Minor device type in hex

%t Major device type in hex

%U User name of owner

%u User ID of owner

%X Time of last access as seconds since Epoch

%x Time of last access

%Y Time of last modification as seconds since Epoch

%y Time of last modification

%Z Time of last change as seconds since Epoch

%z Time of last change

 

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 - Security context in SELinux

%i File System id in hex

%l Maximum length of filenames

%n File name

%s Optimal transfer block size

%T Type in human readable form

%t Type in hex

 

Report bugs to <bug-coreutils@gnu.org>.

 

From the help file for the command stat above , there is some options to use with the stat command.

 

Check file status.

 

Try to issue ' stat ' command and then put name of the file we wish to check the status.

 

[root@fedora ~]# stat install.log

File: `install.log'

Size: 71590 Blocks: 160 IO Block: 4096 regular file

Device: fd00h/64768d Inode: 940994 Links: 1

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2005-10-22 22:41:22.000000000 -0400

Modify: 2005-10-23 03:22:34.000000000 -0400

Change: 2005-10-23 03:22:34.000000000 -0400

 

Then try to issue the same command and now with the -f option to display filesystem status instead of file status.

 

[root@fedora ~]# stat -f install.log

File: "install.log"

ID: 0 Namelen: 255 Type: ext2/ext3

Blocks: Total: 2388558 Free: 593795 Available: 470506 Size: 4096

Inodes: Total: 2466048 Free: 2126726

[root@fedora ~]#

 

   From the example above the command stat can be use to check the file or filesystem status,  this quite useful is you want to check the size of file, file IO block, file Inode number, number of link and access permission granted to the file.

 

NAME

stat - display file or filesystem status

Usage: stat [OPTION] FILE...

 

for more information on stat command:

# info stat

# man stat

# stat --help

 

Step-by-step how to procedure above tested on:

Operating System: GNU/Linux Fedora Core 4

Kernel Name: Linux

Kernel  Release:  2.6.11-1.1369_FC4

Kernel Version: #1 Thu Jun 2 22:55:56  EDT 2005

Machine Hardware:  i686

Machine Processor:  i686

Hardware Platform:  i386

Shell: GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu)

Installation Type: Full  Installation (Custom)

SELinux: Disable

 

Keywords: using stat command, stat command, linux stat command, display file status, filesystem status, check inode, check file ststus, check file permission, check symbolic link, check inode number.

 

aaaaaaaaaaa