Skip to content
shellmap

freeShow used, free, and total RAM (Linux-only) across all 5 shells

Equivalents in every shell

Bashunix
free -h

External binary from `procps-ng`. `-h` is human-readable (`1.2Gi`, `4.5Gi`); `-m` megabytes, `-g` gigabytes. `-s 2` refreshes every 2 seconds (like `watch free`). Linux-ONLY — `free` does not exist on macOS or BSD. The output's `available` column (modern free, 2014+) is what you actually care about for "how much can I allocate without swapping" — NOT the `free` column (which excludes buffer/cache reclaim).

Zshunix
free -h

Same Linux-only external. On macOS, the equivalent is `vm_stat` (reports in pages — multiply by `pagesize` for bytes) plus `sysctl -n hw.memsize` for total. `top -l 1 -s 0 | head -10` shows a Linux-like memory summary on macOS. For a `free`-like one-liner on macOS: `vm_stat | awk '/Pages free:/ {f=$3} /Pages active:/ {a=$3} END {print "free:", f*4/1024, "MiB"}'` (Darwin uses 4KiB pages — but on Apple Silicon Macs the page size is 16KiB; use `pagesize` cmd to read the actual size).

Fishunix
free -h

Same Linux-only external. Fish makes it easy to capture: `set mem (free -m | grep Mem)`. On macOS / BSD, `vm_stat` is the answer; fish syntax `set total (sysctl -n hw.memsize)` then `math $total / 1024 / 1024` for MiB.

PowerShellwindows
Get-CimInstance Win32_OperatingSystem | Select-Object FreePhysicalMemory, TotalVisibleMemorySize

Returns values in KIBIBYTES (1024 bytes), not bytes. Divide by 1024 to get MiB, by 1MB to get MB. For a closer free-style one-liner: `Get-CimInstance Win32_OperatingSystem | ForEach-Object { "{0,8} MiB free of {1,8} MiB" -f ($_.FreePhysicalMemory/1KB), ($_.TotalVisibleMemorySize/1KB) }`. Real-time counters: `Get-Counter "\Memory\Available MBytes"` and `Get-Counter "\Memory\Committed Bytes In Use"`. Per-process: `Get-Process | Sort-Object WS -Descending | Select-Object Name, @{N="WS_MB"; E={[int]($_.WS/1MB)}} -First 10`.

cmd.exewindows
wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /value

Returns values in KIBIBYTES. `wmic` is deprecated since Windows 11 22H2 (2022) but still installed on most boxes through 2026. Modern replacement: `systeminfo | findstr /B /C:"Available Physical Memory" /C:"Total Physical Memory"` (slow ~5s, but always there). Or shell out to pwsh: `powershell -NoProfile -Command "(Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory"`. Task Manager (`taskmgr`) Performance tab is the GUI equivalent for interactive inspection.

Worked examples

Show memory summary in human-readable form

Bash
free -h
Fish
free -h
PowerShell
Get-CimInstance Win32_OperatingSystem | Select-Object @{N="FreeMB"; E={[int]($_.FreePhysicalMemory/1KB)}}, @{N="TotalMB"; E={[int]($_.TotalVisibleMemorySize/1KB)}}
cmd.exe
systeminfo | findstr /B /C:"Available Physical Memory" /C:"Total Physical Memory"

Watch memory usage refresh every 2 seconds

Bash
free -h -s 2
Fish
free -h -s 2
PowerShell
while ($true) { Get-Counter "\Memory\Available MBytes" -ErrorAction SilentlyContinue; Start-Sleep 2; Clear-Host }

Show the top 5 processes by memory usage

Bash
ps aux --sort=-%mem | head -6
PowerShell
Get-Process | Sort-Object WS -Descending | Select-Object -First 5 Name, @{N="WS_MB"; E={[int]($_.WS/1MB)}}
cmd.exe
tasklist /v /fo table | sort /R /+65

Gotchas

  • Linux `free -h` "free" column is misleading on modern kernels — it excludes RAM used by the page cache, which the kernel will reclaim instantly under pressure. The "available" column (added 2014, kernel 3.14) is the real "how much can I allocate without swapping" number. Old SRE alerting that fires on `free < 10%` will scream constantly on a healthy box because the kernel uses spare RAM as cache aggressively. Switch alerts to `available < 10%`.
  • `free` does NOT exist on macOS. Common script-portability bug: a Linux CI script using `free -m` gets ported to a macOS runner and fails with `command not found`. Use the OS branch from `uname -s` first, then `free` on Linux + `vm_stat` on macOS + a Win32_OS query on Windows. Or use a portable tool like `htop` (interactive) or `glances` (Python, cross-platform JSON output).
  • pwsh `Get-CimInstance Win32_OperatingSystem` values are in KIBIBYTES (1024 bytes per unit), not bytes and not MB. `FreePhysicalMemory` of `8388608` means 8 GiB, not 8 MB. Easy mistake when chained to a threshold check — `if ($mem.FreePhysicalMemory -lt 1000000) { alert }` is comparing 1 million KiB (~1 GB) not 1 million bytes (1 MB). Always normalize to a known unit immediately: `$freeGB = [Math]::Round($mem.FreePhysicalMemory / 1MB, 2)` (yes, pwsh `1MB` literal = 1048576, so `KiB / 1MB` = GiB — pwsh's `1KB`/`1MB`/`1GB` literals are all powers of 1024).
  • Windows `Get-Counter "\Memory\Available MBytes"` returns the COMMITTED-available memory — different from `FreePhysicalMemory` (truly idle physical pages). On a Windows box with lots of standby cache, `Available MBytes` will be MUCH higher than `FreePhysicalMemory` because Windows treats standby cache as available. For an apples-to-apples comparison with Linux `free`, use Available, not Free.
  • WSL2 `free -h` reports WSL VM's memory allocation, NOT the Windows host's. By default, WSL2 reserves 50% of host RAM (or 8GB, whichever is less) — `free` inside WSL shows that 8GB ceiling, not your 32GB host. Tune in `%USERPROFILE%\.wslconfig` with `[wsl2] memory=16GB`. To see the actual Windows-host memory from inside WSL: `cmd.exe /c "wmic OS get FreePhysicalMemory,TotalVisibleMemorySize"`.

WSL & PowerShell Core notes

pwsh`Get-CimInstance Win32_OperatingSystem` is Windows-only — on Linux / macOS pwsh, it errors with "no CIM provider". The portable approach: `(Get-Content /proc/meminfo)` on Linux pwsh; `& vm_stat` on macOS pwsh; the CIM query on Windows pwsh. For a single portable abstraction across pwsh-on-everything, install the `PSResourceGet` and use a community module, or hand-write a `Get-MemoryInfo` function that branches on `$IsWindows` / `$IsLinux` / `$IsMacOS`.
WSLInside WSL2, `free` reports the WSL VM allocation (bounded by `.wslconfig` `memory=`). The Windows-side host RAM is visible only via `cmd.exe /c` shimming, which reaches into the Windows host. Common script footgun: WSL container reports 8GB total, the host has 64GB — sizing decisions based on `free` from inside WSL undershoot 8×. For "true host memory available", always shell back out to Windows.

Common tasks using free

Related commands