Beginners Guide for Stat Command on Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

The stat command is used to get detailed information about a file or filesystem, such as the file size, blocks, IO blocks, device type, SELinux security context string, Inode, permissions, and modification date.

Tutorial Details

Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredNo

Syntax of the Stat Command

The stat command takes two arguments: one is the option, and the other is the filename.


Displaying File Properties

If you don’t use any flags, the stat command will show the properties of a specific file by default. These properties include the file’s size, permissions, creation and access dates, and many more.

$ stat file.txt 


Checking the properties of a file

You can specify multiple files by using the space as a separator, like β€œstat file1.txt file2.txtβ€œ.

Displaying File Properties Without Labels

The β€œ-t” or β€œ--terse” flag will return the same result as the previous command by just ignoring the labels.

$ stat -t file.txt 


Checking the minimal file information

Displaying Filesystem Information

The β€œ-f” or β€œ--file-system” flag will print information about the filesystem where a specific file is located.

$ stat -f file.txt 


Examining the referenced file, filesystem-related data

Dereference Symlinks

If you specify the symlinks to the stat command, it will give you information about the symlink instead of the actual file to which it points.

$ stat Documents/file.txt 


Checking the property of a symbolic link

However, you can use the β€œ-L” flag to retrieve information about the actual file or directory to which the symlink points.

$ stat -L Documents/file.txt 


Checking the properties of the actual file

Custom Format to Display File Properties

You can use the β€œ-c” flag to specify the format that will be displayed in newlines.

However, you can also use the β€œ--printf” option, which enables interpreting if a backslash escapes the sequence without a trailing newline.

To enable the trailing newline, use the β€œ\n” in the format to print a new line.

$ stat --printf='%U\n%G\n%B\n%C\n%z\n%F\n' file.txt 


Using custom formatting with the stat command

The following is a description of all the formats used in the above command.

%UUser name of the owner
%GGroup name of owner
%BThe size, in bytes, of each block reported by the %b
%CSELinux security context string
%zTime of last status change, human-readable
%FFile type

The above is not the complete list of formats that stat supports.

The following is the list of valid format sequences:

Valid Format Sequences

%aAccess rights in octal (note β€˜#’ and β€˜0’ printf flags)
%AAccess rights in human readable form
%bNumber of blocks allocated (see %B)
%BThe size in bytes of each block is reported by %b
%CSELinux security context string
%dDevice number in decimal
%DDevice number in hex
%fRaw mode in hex
%FFile type
%gGroup ID of owner
%GGroup name of owner
%hNumber of hard links
%inode number
%mMount point
%nFile name
%NQuoted file name with dereference if symbolic link
%oOptimal I/O transfer size hint
%sTotal size, in bytes
%tMajor device type in hex, for character/block device special files
%TMinor device type in hex, for character/block device special files
%uUser ID of owner
%UUser name of owner
%wTime of file birth, human-readable; – if unknown
%WTime of file birth, seconds since Epoch; 0 if unknown
%xTime of last access, human-readable
%XTime of last access, seconds since Epoch
%yTime of last data modification, human-readable
%YTime of last data modification, seconds since Epoch
%zTime of last status change, human-readable
%ZTime of last status change, seconds since Epoch

The following is a list of valid file format sequences for file systems.

%aFree blocks available to non-superuser
%bTotal data blocks in file system
%cTotal file nodes in file system
%dFree file nodes in file system
%fFree blocks in file system
%iFile system ID in hex
%lMaximum length of filenames
%nFile name
%sBlock size (for faster transfers)
%SFundamental block size (for block counts)
%tFile system type in hex
%TFile system type in human readable form

That’s the end, sayonara!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.