Is there any way to change the default line length for the od and hexdump commands? Can't see anything apropriate in the man pages.
Asked
Active
Viewed 1.3k times
6
newenglander
- 593
- 2
- 5
- 7
3 Answers
10
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:
3
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.
jsbillings
- 24,006
- 6
- 56
- 58
-
hey thanks for the tip about `width` in `od`, my man pages didn't have that! – newenglander May 04 '12 at 22:05
-
1@newenglander as mentioned under SEE ALSO you should also check `info coreutils 'od invocation'`. – Thor May 04 '12 at 22:09
-
With anything GNU, it's always a good idea to check the info page. It has much more information. – jsbillings May 04 '12 at 22:09
-
Thanks for the extra tip, my SEE ALSO only had _hexdump(1), strings(1)_. – newenglander May 04 '12 at 22:15
-
Calling `info coreutils 'od invocation'` on my systems (Mac OS X, FreeBSD) gives me the message `No 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 the `man` page on that system). – newenglander May 06 '12 at 14:37
-
@newenglander: The `od` and `hexdump` 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. – jsbillings May 06 '12 at 19:46
2
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
ArcherGodson
- 141
- 2