Skip to content

stat MacOS command

The stat command on MacOS is a useful tool for viewing detailed information about files, such as their size, permissions, timestamps, and more. This command provides a way to access metadata that is not easily visible through the regular user interface. By using the stat command, you can quickly retrieve various attributes of a file, helping you to manage and work with files more effectively. Whether you need to check the last modification time of a file or verify its size, the stat command gives you a comprehensive overview of the file’s metadata at a glance. Familiarizing yourself with this command can enhance your productivity when working with files on MacOS.

stat Syntax:

Terminal window
stat [option] [filename]

Options:

OptionDescription
-fDisplay information in filesystem format
-sDisplay only size information
-tDisplay information in terse format
-xDisplay information in XML format

Parameters:

ParameterDescription
filenameThe name of the file to get details for

stat bash Examples:

Check File Information

Terminal window
stat file.txt

Displays detailed information about the file “file.txt”.

Display Information in Human-Readable Format

Terminal window
stat -f file.txt

Shows the file information in a human-readable format.

Check Inode Information

Terminal window
stat -f file.txt

Retrieves the inode details of the file “file.txt”.

Display Information in Numeric Format

Terminal window
stat -f file.txt -c "%i %s"

Shows specific file details in a numeric format.

Check Access and Modified Time

Terminal window
stat -f file.txt -c "%x %y"

Displays the access and modified times of the file “file.txt”.

Show File Size in Bytes

Terminal window
stat -f file.txt -c "%s"

Outputs the file size in bytes for “file.txt”.

stat Command Help Center:

How do I use stat in MacOS?

To use the stat command in MacOS, execute the following command:

Terminal window
stat --option <value>

How can I display information about a file using stat in MacOS?

To display information about a file using stat in MacOS, use the following command:

Terminal window
stat /path/to/file

How do I get the output in a specific format with stat in MacOS?

To get the output in a specific format with stat in MacOS, you can use the following command:

Terminal window
stat -f "Format string" /path/to/file

How can I show only the permissions of a file with stat in MacOS?

To show only the permissions of a file using stat in MacOS, you can run the following command:

Terminal window
stat -f "%Sp" /path/to/file

How can I get the size of a file in a human-readable format with stat in MacOS?

To get the size of a file in a human-readable format using stat in MacOS, you can use the following command:

Terminal window
stat -f "%z" /path/to/file

How do I display the last access time of a file with stat in MacOS?

To display the last access time of a file using stat in MacOS, you can run the following command:

Terminal window
stat -f "%Sa" /path/to/file

How can I view the inode number of a file with stat in MacOS?

To view the inode number of a file using stat in MacOS, you can use the following command:

Terminal window
stat -f "%i" /path/to/file

How do I show the birth time (creation time) of a file with stat in MacOS?

To show the birth time (creation time) of a file using stat in MacOS, you can execute the following command:

Terminal window
stat -f "%SB" /path/to/file

Applications of the stat command

  • Checking file permissions
  • Viewing file size
  • Displaying file creation, modification, and access times
  • Checking file type
  • Retaining file information for scripting purposes