Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to understand the formatting option of hexdump. I have read the man page and it says that I can tell it what format to output the data in by using the -e option. However, I can not for the life of me understand the code for the option. For now, I'm just trying to have it print random lines from /dev/random like this:


(Basically, a psuedo IPv6 address.) However, I would really like to understand the formatting strings, not just have one that does the trick. I have tried reading the man page and it wasn't much help--it seemed to refer to it being similar to C code. Well, I have almost no experience with C, so I'm stuck. Can somebody please explain this?

share|improve this question
up vote 5 down vote accepted

In the manual page for hexdump, there is an entire section dedicated to the structure of the format strings (search for "A format string contains any number of format units").

To get the output you are after, the following invocation should do the trick:

hexdump -e '7 2 "%04X:" 1 2 "%04X\n"' input_file

The format string here has two parts. The first is repeated 7 times, formatting two bytes at a time formatted with "%04X:" (four hexadecimal digits with zero padding, followed by a colon). The second part is repeated once only and takes two bytes formatted with "%04X\n" to complete the line of output. This process is then repeated as more data is read from the input file.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.