Skip to content
shellmap

hexdumpBSD-style hex dump with custom format strings — default on macOS across all 5 shells

Equivalents in every shell

Bashunix
hexdump -C file.bin

`-C` is canonical mode: offset (hex) + 16 bytes hex + ASCII gutter — the most useful default. Without `-C`, the default is `-x` (word view, 2-byte groups) which surprises everyone. `-n LEN` limits length, `-s OFFSET` starts at a byte offset. Linux ships hexdump via `util-linux` (always present).

Zshunix
hexdump -C file.bin

macOS ships BSD hexdump in `/usr/bin/hexdump` — same flags as Linux util-linux's hexdump (BSD-derived). `-C` is the standard interactive form. macOS's BSD hexdump also accepts `-x`, `-d` (decimal), `-o` (octal) and `-e` (custom format) identically.

Fishunix
hexdump -C file.bin

Same external binary. Fish piping is identical. `hexdump -C file.bin | psub` (process substitution) is fish's clean way to feed two hex dumps to `diff` without temp files.

PowerShellwindows
Format-Hex file.bin

pwsh-native — covers both `xxd` and `hexdump -C` use cases. Output format differs (different column alignment, no flags for format strings). For BSD hexdump's `-e` format-string flexibility, install hexdump via Git for Windows or WSL.

cmd.exewindows
certutil -dump file.bin

No native cmd.exe hex viewer. Git for Windows installs hexdump alongside the bundled coreutils — add `C:\Program Files\Git\usr\bin` to PATH, then `hexdump -C` works in cmd.

Worked examples

Show the first 64 bytes in canonical hex + ASCII gutter

Bash
hexdump -C -n 64 file.bin
PowerShell
Format-Hex file.bin -Count 64

Emit one byte per line as decimal (for awk/sort pipelines)

Bash
hexdump -v -e '/1 "%d\n"' file.bin
PowerShell
[IO.File]::ReadAllBytes('file.bin') | ForEach-Object { $_ }

Compare two binaries byte-for-byte using hex dumps

Bash
diff <(hexdump -C a.bin) <(hexdump -C b.bin)
PowerShell
Compare-Object (Format-Hex a.bin) (Format-Hex b.bin)

Gotchas

  • The DEFAULT hexdump output (no flags) is NOT the canonical hex+ASCII view — it's `-x` (2-byte word groups, no ASCII gutter). Always pass `-C` for the interactive view people expect. The default exists for backward compatibility with v6/v7 Unix scripts.
  • `-e FORMAT` uses an arcane `awk`-like format string language: `/COUNT "FORMAT"` repeats FORMAT for each COUNT bytes. `/1 "%02x "` is single-byte hex; `/4 "%08x "` is 4-byte big-endian. The trailing space / newline matters. Not for ad-hoc one-liners.
  • BSD `hexdump` (macOS) and util-linux `hexdump` (Linux) are essentially the same code lineage — flags match for `-C`, `-n`, `-s`, `-e`. But the underlying default output is locale-stable: `LC_ALL=C hexdump` is safe; non-C locales can change the ASCII gutter for byte values > 127.
  • `hexdump -v` (verbose) disables the `*` placeholder that hexdump uses to compress repeated lines (e.g. long runs of zeros). Without `-v`, the output is shorter but breaks when piping to `diff` for byte-comparison — always pair with `-v` for diffable output.
  • There's no `hexdump --reverse` — hexdump only writes, not reads back. For round-trip (binary → hex → binary), use `xxd -r` instead (xxd is the reversible tool; hexdump is the formatter).

WSL & PowerShell Core notes

pwsh`Format-Hex` covers `hexdump -C` use cases — display only, no format strings, no reverse. For BSD hexdump's full feature set, install via Git for Windows (bundles util-linux hexdump) or WSL. Cross-shell scripts that need byte-identical hex output should standardise on `xxd -p` (plain hex), available on every platform via the vim distribution.
WSLWSL `hexdump -C /mnt/c/path/to/file.bin` works transparently. WSL's `hexdump` is from util-linux (Linux flavour) — matches Linux distros exactly. Don't expect WSL hexdump output to byte-match macOS BSD hexdump output character-for-character; column widths may differ slightly.

Related commands