How to change the default line length for od and hexdump
10,786
Solution 1
od
has the --width=N
argument, which you can use to choose how many bytes per line, perhaps that's what you're looking for? hexdump
has a -e FORMATSTRING
which has promise, but I've never played too much with it.
Solution 2
I know this is an old question, but for completeness, here is an example hexdump command that prints 8 bytes per line:
hexdump -e '8/1 " %02X" "\n"' <file>
More information about hexdump format strings can be found at these links:
- https://stackoverflow.com/questions/26694065/hexdump-how-to-change-number-of-columns
- https://www.suse.com/communities/blog/making-sense-hexdump/
Solution 3
I found the way to make -C | --canonical like but width-wide
hexdump -e '"%08_ax " '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))'/1 "%02x " " |" '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))'/1 "%_p" /0 "| \n"'
just change '$(($(tput cols 2> /dev/null || echo $COLUMNS ) / 4 - 4 ))' to your value
Related videos on Youtube
![newenglander](https://i.stack.imgur.com/3hgRu.png?s=256&g=1)
Author by
newenglander
Updated on September 18, 2022Comments
-
newenglander almost 2 years
Is there any way to change the default line length for the
od
andhexdump
commands? Can't see anything apropriate in the man pages. -
Thor about 12 years@newenglander as mentioned under SEE ALSO you should also check
info coreutils 'od invocation'
. -
jsbillings about 12 yearsWith anything GNU, it's always a good idea to check the info page. It has much more information.
-
newenglander about 12 yearsThanks for the extra tip, my SEE ALSO only had hexdump(1), strings(1).
-
newenglander about 12 yearsCalling
info coreutils 'od invocation'
on my systems (Mac OS X, FreeBSD) gives me the messageNo menu item 'coreutils' in node '(dir)Top'.
But I did try it on Linux and it was indeed more helpful (but then again so was theman
page on that system). -
jsbillings about 12 years@newenglander: The
od
andhexdump
on MacOSX isn't the GNU version, but BSD. They're different implementations than the GNU utilities, so no info pages. Good to hear that the--width
argument works. -
Admin about 2 yearsGood digging - thanks for this!