Skip to content
shellmap

Show system uptime

Display how long the system has been running since the last boot.

How to show system uptime in each shell

Bashunix
uptime -p

`uptime -p` (pretty) prints `up 3 weeks, 2 days, 4 hours, 15 minutes`. Bare `uptime` adds load averages + user count: `15:32:18 up 23 days, 4:15, 2 users, load average: 0.45, 0.32, 0.28`. `uptime -s` prints the boot timestamp itself (`2026-04-23 11:17:03`).

Zshunix
uptime

macOS BSD `uptime` has NO `-p` / `-s` flags — output is fixed to the load-average format. For pretty form on macOS: `awk '{print int($1/86400)" days, "int(($1%86400)/3600)" hours"}' /proc/uptime` does NOT work (no /proc on macOS) — use `sysctl -n kern.boottime` to get the boot epoch, then date-math.

Fishunix
uptime -p

Same external `uptime`. Fish status check: `if test (uptime -s) = (date -d "5 minutes ago" +"%Y-%m-%d %H:%M:%S"); echo just rebooted; end`.

PowerShellwindows
(Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime

Returns a `[TimeSpan]` (e.g. `Days: 23, Hours: 4, Minutes: 15`). pwsh 6+: `Get-Uptime` cmdlet returns the same `[TimeSpan]` directly. The `Win32_OperatingSystem` WMI class is available on all Windows. For just the boot timestamp: `(Get-CimInstance Win32_OperatingSystem).LastBootUpTime` returns a `[DateTime]`.

cmd.exewindows
systeminfo | find "System Boot Time"

`systeminfo` is slow (5–15 seconds — it queries every WMI class). For a fast answer: `powershell -Command "(Get-CimInstance Win32_OperatingSystem).LastBootUpTime"`. `net statistics workstation | find "Statistics since"` also reports a boot-adjacent time but it's the SERVICE start time, not the OS boot time — they differ if the workstation service was restarted.

Equivalents listed for Bash, Zsh, Fish, PowerShell, cmd.exe.

Gotchas & notes

  • **Boot time vs uptime**: "uptime" is the DURATION; "boot time" is the TIMESTAMP. `uptime -p` gives `up X days, Y hours`; `uptime -s` gives `2026-04-23 11:17:03`. pwsh `(Get-Date) - $boot` is the duration; `$boot` itself is the timestamp. Confusing them silently breaks `since-last-reboot` log filters.
  • **Suspended / hibernated machines**: on macOS / Windows laptops, "uptime" includes time spent suspended (S3 / modern-standby) but NOT time spent hibernated (S4 — RAM written to disk, kernel restored from disk on resume). A 7-day-uptime laptop that was hibernated for 5 of those days shows `uptime 7d` but only 48 hours of actual running. Linux behaves the same: kernel monotonic clock pauses across suspend on most distros, doesn't across hibernate.
  • **WMI / CIM LastBootUpTime format**: pwsh 5.1 `(Get-WmiObject Win32_OperatingSystem).LastBootUpTime` returns a CIM datetime STRING like `20260423111703.500000+060` (date+microseconds+TZ offset) — you must call `[Management.ManagementDateTimeConverter]::ToDateTime($_)` to parse. pwsh 7+ `Get-CimInstance` returns a real `[DateTime]` directly (no conversion needed). The legacy `Get-WmiObject` cmdlet still works on 7+ but is deprecated.
  • **Container / VM caveats**: inside a Docker/Podman container, `uptime` reports the HOST kernel uptime (`/proc/uptime` is namespace-shared on Linux), not the container lifetime. For container uptime, use `docker inspect -f '{{.State.StartedAt}}' <container>` or `kubectl get pod -o jsonpath='{.status.startTime}'`. In a VM, `uptime` is correct for the guest OS — independent of host.

Related tasks