Skip to content
shellmap

statPrint a file's size, mode, owner, and timestamps across all 5 shells

Equivalents in every shell

Bashunix
stat file.txt

GNU coreutils — Linux default. Use `-c FORMAT` for a specific field.

Zshunix
stat file.txt
Fishunix
stat file.txt
PowerShellwindows
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.txt
Fish
stat -c %s file.txt
PowerShell
(Get-Item file.txt).Length
cmd.exe
for %A in (file.txt) do @echo %~zA

Print the file mode in octal (rwx → 0644 etc.)

Bash
stat -c %a file.txt
PowerShell
# 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.txt
PowerShell
[int64]((Get-Item file.txt).LastWriteTimeUtc - (Get-Date "1970-01-01Z")).TotalSeconds

Gotchas

  • 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

Related commands