brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: hexdump -C shows a file as hex bytes next to readable text

CLI
~/tips/tip-hexdump-canonical-view

printf 'GET /\r\n' | hexdump -C

See the exact bytes of a file, with hex on the left and readable characters on the right.

Sometimes a file looks fine in an editor and still breaks a script. A stray carriage return, a byte order mark or an odd space is hard to see, so I look at the raw bytes.

hexdump -C prints the canonical view: the offset, the bytes in hex, and the same bytes as text on the right.

printf 'GET /\r\n' | hexdump -C

The output shows 47 45 54 20 2f 0d 0a and |GET /..| on the right. The 0d 0a at the end is a Windows line ending, and the two dots are the non-printable bytes. Plain cat would hide that difference.

Pass a file name instead of the pipe to look at a real file. By default hexdump squeezes repeated identical lines into a single *; add -v if you want every line printed.

A caveat: on Debian and Ubuntu hexdump comes with the bsdextrautils package, so a minimal install may not have it. xxd or od -c do a similar job.

Further reading: hexdump man page

More CLI tips hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' yt-dlp --download-archive archive.txt "https://www.youtube.com/playlist?list=PLAYLIST_ID" All CLI tips (46) All topics

Link