stat — Print a file's size, mode, owner, and timestamps across all 5 shells
Equivalents in every shell
Zshunix
stat file.txtFishunix
stat file.txtPowerShellwindows
Get-Item file.txt | Format-List *Lists every property of the `FileInfo` object — `.Length`, `.LastWriteTime`, `.CreationTime`, `.Mode`, etc.
cmd.exewindows
dir file.txt`dir` shows size and modified date but not mode, owner, or atime. For more detail use `forfiles /M file.txt /C "cmd /c echo @file @fsize @fdate @ftime"`.
Worked examples
Print just the file size in bytes
Bash
stat -c %s file.txtFish
stat -c %s file.txtPowerShell
(Get-Item file.txt).Lengthcmd.exe
for %A in (file.txt) do @echo %~zAPrint the file mode in octal (rwx → 0644 etc.)
Bash
stat -c %a file.txtPowerShell
# Windows uses ACLs; no octal mode equivalent. (Get-Item file.txt).Mode shows the four-char d/a/r/h attribute string.Print the last-modified time as a Unix timestamp
Bash
stat -c %Y file.txtPowerShell
[int64]((Get-Item file.txt).LastWriteTimeUtc - (Get-Date "1970-01-01Z")).TotalSecondsGotchas
- GNU `stat` (Linux) uses `-c FORMAT`; BSD `stat` (macOS pre-Sonoma, FreeBSD) uses `-f FORMAT` with completely different specifiers (`%z` for size on BSD vs `%s` on GNU). Scripts that need to run on both should detect the platform or install GNU coreutils via Homebrew.
- Windows has no Unix-style mode bits — `(Get-Item).Mode` returns a four-character attribute string (e.g. `d----`, `-a---`), not an octal mode. Use `Get-Acl` for the real permission picture.
- The "access time" (atime) is unreliable on Windows (often disabled to save IO) and on Linux mounts with `noatime`. Treat it as advisory at best.
- macOS Sonoma ships a `stat` that accepts a `-c` flag for GNU compatibility — but only since 14.0. Earlier macOS versions error out on `-c`.
- `Get-Item -Force` is needed to see hidden files; without it, `stat`-equivalent calls on dotfiles or `$HOME\NTUSER.DAT` fail with "Cannot find path".
WSL & PowerShell Core notes
pwshPowerShell Core has no `stat` cmdlet. `Get-Item` and `Get-ChildItem` are the canonical equivalents and surface the same `.Length` / `.LastWriteTime` / `.CreationTime` properties on every platform. On Linux/macOS pwsh, the system `stat` binary still works for octal-mode output that `Get-Item` cannot produce.
WSLOn `/mnt/c/...`, `stat` reports POSIX permissions reconstructed from NTFS ACLs by DrvFs — they are not real mode bits. The reported owner is usually `root` unless `metadata` is enabled in `/etc/wsl.conf` and the file was created from inside WSL.
Common tasks using stat
- Check if a file exists
Test whether a file (or directory, or symlink) exists at a path before reading, writing, or branching script logic.
- Get a file size in bytes
Print the size of a file in bytes — for quotas, validation, and disk-usage scripts.
- Get file modification time
Print the last-modification timestamp of a file — useful for cache invalidation, build-system checks, and freshness validation.