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 -s and -n look at just a slice of a big file

CLI
~/tips/tip-hexdump-skip-length

hexdump -C -s 512 -n 64 disk.img

Show only a chosen slice of a file in hex instead of the entire thing.

Dumping a whole disk image or a large backup in hex is pointless when I only care about the first few bytes, or one spot further in.

-n limits the number of bytes read and -s skips a number of bytes from the start. Together they select a slice:

hexdump -C -n 16 firmware.bin
hexdump -C -s 512 -n 64 disk.img

The first line shows the first 16 bytes, often enough to see a file signature. The second skips 512 bytes and shows the next 64. Both accept size suffixes, so -s 1KiB works too.

A caveat: the offset printed on the left starts counting at the skipped position, so it shows where you are in the file, not from the start of your slice.

Further reading: hexdump man page

More CLI tips printf 'GET /\r\n' | hexdump -C 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