11

If I opened hexdump without any argument in the terminal:

hexdump 

When I type something in the terminal and press Enter, hexdump will display the hex values for whatever characters I type.

But hexdump will only display the hex values if I type 16 characters, for example:

enter image description here

Here, I typed the character a 15 times and I pressed Enter(so hexdump received 16 characters (15a + \n)).

But if I type less than 16 characters, for example:

enter image description here

Here, I typed the character a 14 times and I pressed Enter(so hexdump received 15 characters (14a + \n)). And in this case hexdump did not display anything.

Can I make hexdump display the hex values for whatever length of characters it receives instead of it waiting for 16 characters to be received?

Note: I do not want to "use options both for hexdump and xxd to display one byte as hex per line" (as suggested in a comment here). What I want to do basically is for example to know what the hex value for A without having to type an extra 15 characters to get it.

3
  • IIRC output lines are buffered by default, not sure ATM if you can change that from the shell. But you can use options both for hexdump and xxd to display one byte as hex per line, would that be acceptable? Commented Nov 4, 2017 at 7:56
  • Try hexdump -v -e '/1 "%02X\n"'. Then you only have to type A and return to know the hex value for A. You still have to type return, because the shell buffers the input line. man ascii also works. :-) Commented Nov 4, 2017 at 8:55
  • Unneeded screenshots are evil, please use text copy-paste if it is possible. Commented Feb 8, 2018 at 12:06

2 Answers 2

4

Try hexdump -v -e '/1 "%02X\n"'. That displays one hex byte per line, so the line output buffering won't stop the line from being displayed.

Then you only have to type A and return to know the hex value for A. You still have to type return, because the shell buffers also does line buffering on the input.

man ascii also works. :-)

0

It's possible to write to same line unbuffered wrapping hexdump to stdbuf. Bash example (requires it due to some read command options):

while read -s -n1 k; do printf $k; done | stdbuf -o0 hexdump -e '1/1 "%x"' 
1
  • thanks for the hexdump $1 -v -e '1/1 "%x "' Commented Apr 25, 2024 at 11:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.