Read exact file timestamps with stat
macOS stat uses BSD syntax with -f format strings, which surprises people who know the Linux form; it shows access, modification, and inode-change times to the second.
Run `stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" file.txt` to print the modification time in a chosen format.
01Command
Command
$ stat -f "%N | modified: %Sm | accessed: %Sa" report.txt
stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S" report.txt02What it does
The format verbs %Sa, %Sm, and %Sc give access, modification, and status-change times respectively, while %N prints the file name and %z the size in bytes. Unlike ls, stat never truncates or rounds times, making it the right tool for verifying timestamp forensics or backup tool behavior — and remember it is BSD stat, not the GNU -c variant.
03Risk
!Warning: The Linux-style `stat -c '%y' file` fails on macOS ('illegal option'); the BSD form needs -f plus format strings.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- stat — display file status (macOS)Evidence: Documents the BSD -f format strings %Sm/%Sa/%Sc and -t timestamp output format.
Last verified: 2026-09-17 · Category: Files & Folders