hexdump — BSD-style hex dump with custom format strings — default on macOS across all 5 shells
Equivalents in every shell
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).
hexdump -C file.binmacOS 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.
hexdump -C file.binSame 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.
Format-Hex file.binpwsh-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.
certutil -dump file.binNo 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
hexdump -C -n 64 file.binFormat-Hex file.bin -Count 64Emit one byte per line as decimal (for awk/sort pipelines)
hexdump -v -e '/1 "%d\n"' file.bin[IO.File]::ReadAllBytes('file.bin') | ForEach-Object { $_ }Compare two binaries byte-for-byte using hex dumps
diff <(hexdump -C a.bin) <(hexdump -C b.bin)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).