LinuxCommandLibrary

stat

Display file or filesystem status

TLDR

Display properties about a specific file such as size, permissions, creation and access dates among others

$ stat [path/to/file]
copy

Display properties about a specific file such as size, permissions, creation and access dates among others without labels
$ stat [[-t|--terse]] [path/to/file]
copy

Display information about the filesystem where a specific file is located
$ stat [[-f|--file-system]] [path/to/file]
copy

Show only octal file permissions
$ stat [[-c|--format]] "%a %n" [path/to/file]
copy

Show the owner and group of a specific file
$ stat [[-c|--format]] "%U %G" [path/to/file]
copy

Show the size of a specific file in bytes
$ stat [[-c|--format]] "%s %n" [path/to/file]
copy

SYNOPSIS

stat [OPTION]... FILE...

PARAMETERS

-L, --dereference
    Follow links.

-f, --file-system
    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 newline after each use of FORMAT.

-t, --terse
    Print the information in a concise, machine-readable format.

-n, --no-dereference
    do not follow links (default).

--help
    Display a help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The `stat` command in Linux displays detailed information about a file or a file system. This includes attributes like file size, access and modification times, permissions, user and group ownership, device numbers, inode number, and file system type. It's a powerful tool for understanding the characteristics of files and directories, essential for system administration, debugging, and general file management. The command can also dereference symbolic links, providing information about the target file instead of the link itself. By default, `stat` prints the information in a human-readable format, but it also allows customizing the output format using `--format` or `-c` options, enabling scripting and automation. Understanding `stat` is useful for determining the age of files, ensuring proper permissions, diagnosing file system issues, or integrating file metadata into other processes. It's a versatile command that every Linux user should be familiar with.

CAVEATS

The output format can vary slightly between different Linux distributions and versions of the `stat` utility. Relying on a specific output format in scripts may lead to compatibility issues. The availability of certain fields might depend on the underlying file system.

FORMAT SEQUENCES

%a access rights in octal.
%A access rights in human readable format.
%b number of blocks allocated (see %B).
%B size in bytes of each block reported by %b.
%C SELinux security context string.
And many others.

HISTORY

The `stat` command is a standard utility in Unix-like operating systems, evolving from earlier file information utilities. Its purpose has always been to provide detailed metadata about files and file systems, aiding in system administration and software development. Over time, it has gained more features, such as customizable output formats, to better support scripting and automation. Its inclusion in the GNU coreutils package has ensured its widespread availability across Linux distributions.

SEE ALSO

ls(1), find(1), du(1)

Copied to clipboard